Hello, 

I want to set the address of a global uninitialized variable which is in the
.bss ( COMMON ) section
for a PC-program at win32.
Can this be done by a linker script file ( gcc linker ld ) ? 
I haven't been successful yet. 
I don't want to modify the source code by adding an "attribute". 

example c-file:
#include <stdio.h>
int xx1; 
int xx2 = 10;
const int xx3 = 20;
int main ( void ) 
{ 
   printf("address(xx1): 0x%08X\n", &xx1 );
   printf("address(xx2): 0x%08X\n", &xx2 );
   printf("address(xx3): 0x%08X\n", &xx3 ); 
   return 0;   
}

The variable xx1  should be always at the same defined address, e.g.
0x404100, 
independent of the link order of other modules.

This linker script does NOT lead to the wanted result, something must be
wrong:

SECTIONS
{
  .text : { *(.text) }
  .data : { *(.data) }
  .bss  : { *(.bss) *(COMMON) }

  COMMON 0x404100 : AT(0x404100) {
   txx.o(COMMON)
}

The output result of the program now is
address(xx1): 0x00404060
address(xx2): 0x00402000
address(xx3): 0x00403000

but it should be this:
address(xx1): 0x00404100
address(xx2): 0x00402000
address(xx3): 0x00403000

Can anyone help?

thanks
-- 
View this message in context: 
http://www.nabble.com/gnu-linker-%28-gcc-ld-%29-set-global-uninitialized-variable-to-a-defined-address-tp19595140p19595140.html
Sent from the gcc - Gnu Help List mailing list archive at Nabble.com.



_______________________________________________
help-gplusplus mailing list
help-gplusplus@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gplusplus

Reply via email to