Linking the script linker file to the source code

I am new to GNU compiler.

I have C source code containing some structures and variables in which I need to place certain variables in certain places.

So, I wrote a script linker file and used C. to declare the variable in the source code. __ attribute__("SECTION")

I use the GNU compiler (cygwin) to compile the source code and create the .hex file using the parameter -objcopy, but I don't get how to link the script linker file at compilation to move the variables accordingly.

I am linking the script linker file and the C source file for the link.

Please help me link the script linker file to my source code by creating a .hex file using GNU.

/*linker script file*/
/*defining memory regions*/

      MEMORY
      {
         base_table_ram     : org = 0x00700000, len = 0x00000100  /*base table area for BASE table*/ 
         mem2               : org =0x00800200,  len = 0x00000300 /* other structure variables*/
      }
/*Sections directive definitions*/ 

      SECTIONS
      {
        BASE_TABLE    : { }  > base_table_ram

        GROUP                  :
           {
                   .text        : { } { *(SEG_HEADER)  }
                   .data        : { } { *(SEG_HEADER)  }
                   .bss         : { } { *(SEG_HEADER)  }

           } > mem2

      }

Source Code C:

const UINT8 un8_Offset_1 __attribute__((section("BASE_TABLE")))  = 0x1A; 
const UINT8 un8_Offset_2 __attribute__((section("BASE_TABLE")))  = 0x2A; 
const UINT8 un8_Offset_3 __attribute__((section("BASE_TABLE")))  = 0x3A; 
const UINT8 un8_Offset_4 __attribute__((section("BASE_TABLE")))  = 0x4A; 
const UINT8 un8_Offset_5 __attribute__((section("BASE_TABLE")))  = 0x5A;     
const UINT8 un8_Offset_6 __attribute__((section("SEG_HEADER")))  = 0x6A; 

, "BASE_TABLE" , script, "SEG_HEADER", script.

, .hex , , 0x00, linker script.

, script .

- script, - , .

,

SureshDN.

+5
3

gcc -Xlinker -T (linker script name) (c sources files)

+2

c , :

gcc -Xlinker -T"xxx.lds" (all object files)

gcc:

`-Xlinker OPTION'
    Pass OPTION as an option to the linker.  You can use this to
    supply system-specific linker options which GNU CC does not know
    how to recognize.
+2

,

I found another linker option in GCC, "ld", and the -T option to bind sections to the source code.

ld -T (linker scriptname) -o (final objfile) (objectfile of source file)

Thanks Suresh

+2
source

All Articles