Thread: MinGw GCC Linker Directive help

  1. #1
    Registered User
    Join Date
    Jan 2011

    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.


    In default.ld

    In test.c

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

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    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:
              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")));
                /* 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.

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-14-2010, 12:11 AM
  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