MinGw GCC Linker Directive help

This is a discussion on MinGw GCC Linker Directive help within the C Programming forums, part of the General Programming Boards category; Hi all, I want to know whether it is possible to provide an specific area of memory using the Linker ...

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    1

    MinGw GCC Linker Directive help

    Hi all,

    I want to know whether it is possible to provide an specific area of memory using the Linker Directive File.
    I know this can be done using a different compiler but just not if GCC can do this.

    E.g.

    In default.ld

    Code:
    SECTION
    {
      SOME_MEMORY_ADDRESS 0xFF100000 LENGTH(4) :
    }
    In test.c

    Code:
    #define RSET_CPU_REG (0xFF100000)
    
    int main()
    {
      *((unsigned int*)RSET_CPU_REG) = 0x0000003F;
      return 0;
    }
    Thanks, ;-)
    Rudolf
    Last edited by RErasmus; 01-04-2011 at 02:15 PM. Reason: make more readable

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,558
    From the gcc manual page
    `section ("SECTION-NAME")'
    Normally, the compiler places the objects it generates in sections
    like `data' and `bss'. Sometimes, however, you need additional
    sections, or you need certain particular variables to appear in
    special sections, for example to map to special hardware. The
    `section' attribute specifies that a variable (or function) lives
    in a particular section. For example, this small program uses
    several specific section names:
    Code:
              struct duart a __attribute__ ((section ("DUART_A"))) = { 0 };
              struct duart b __attribute__ ((section ("DUART_B"))) = { 0 };
              char stack[10000] __attribute__ ((section ("STACK"))) = { 0 };
              int init_data __attribute__ ((section ("INITDATA")));
    
              main()
              {
                /* Initialize stack pointer */
                init_sp (stack + sizeof (stack));
    
                /* Initialize initialized data */
                memcpy (&init_data, &data, &edata - &data);
    
                /* Turn on the serial ports */
                init_duart (&a);
                init_duart (&b);
              }
    Having given a particular variable a section name, you would then use the linker to place that section at the address you want.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling GNU MP
    By mattnp12 in forum C Programming
    Replies: 3
    Last Post: 06-23-2011, 03:58 PM
  2. Undefined reference to.. probably Makefile problem
    By mravenca in forum C Programming
    Replies: 11
    Last Post: 10-20-2010, 04:29 AM
  3. Compiling gcc for Windows (MinGW)
    By carrotcake1029 in forum Windows Programming
    Replies: 0
    Last Post: 03-13-2010, 11:11 PM
  4. Undefined reference to...
    By legendus in forum C Programming
    Replies: 19
    Last Post: 10-25-2009, 06:18 AM
  5. Buidl Library with ./configure script
    By Jardon in forum C Programming
    Replies: 6
    Last Post: 07-24-2009, 09:36 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21