Symbols defined via linker script: local or global?
Sebastian Huber
sebastian.huber@embedded-brains.de
Thu Jul 7 05:56:00 GMT 2016
Hello,
sorry for the delay. I have now a test case. It seems to be related to
the --gc-sections option.
I used "ld --verbose > linkcmds" to get the default linker command file
on my Linux machine and removed the header and trailer.
Test program:
extern char SA[];
extern char SC[];
extern char SE[];
__attribute__((section(".my"))) int i;
static const char *const t[] = { SA, SC, SE };
int main()
{
return (int)(long)t;
}
Test linker command file:
SA = 4;
SB = 8;
SECTIONS {
.my : {
SC = .;
SD = .;
KEEP (*(.my*))
}
SE = SC;
SF = SD;
}
INCLUDE linkcmds
We get:
gcc -T linkcmds.my test.c
objdump -t a.out | grep '\<S[A-F]\>'
0000000000000000 g .my 0000000000000000 SD
0000000000000008 g *ABS* 0000000000000000 SB
0000000000000000 g .my 0000000000000000 SF
0000000000000000 g .my 0000000000000000 SC
0000000000000004 g *ABS* 0000000000000000 SA
0000000000000000 g .my 0000000000000000 SE
gcc -T linkcmds.my test.c -Wl,--gc-sections
objdump -t a.out | grep '\<S[A-F]\>'
0000000000000000 l .my 0000000000000000 SD
0000000000000008 l *ABS* 0000000000000000 SB
0000000000000000 g .my 0000000000000000 SF
0000000000000000 g .my 0000000000000000 SC
0000000000000004 g *ABS* 0000000000000000 SA
0000000000000000 g .my 0000000000000000 SE
So, the --gc-sections turns SB and SD into local symbols in contrast to
SA and SE which are referenced by t.
On 12/05/16 14:43, Sebastian Huber wrote:
>
>
> On 12/05/16 14:42, Alan Modra wrote:
>> On Thu, May 12, 2016 at 02:17:41PM +0200, Sebastian Huber wrote:
>>> >
>>> >
>>> >On 12/05/16 14:15, Alan Modra wrote:
>>>> > >On Thu, May 12, 2016 at 01:04:52PM +0200, Sebastian Huber wrote:
>>>>> > >>Hello,
>>>>> > >>
>>>>> > >>I define a symbol in a custom linker script, e.g.
>>>>> > >>
>>>>> > >>foo = 0x123;
>>>>> > >>
>>>>> > >>In case I reference this symbol in my executable (e.g.
>>>>> printf("%p\n", foo)),
>>>>> > >>then the symbol is global in the ELF file. In case it is not
>>>>> referenced by
>>>>> > >>the executable, then it is local.
>>>> > >What target, and what options were you passing to ld?
>>>> > >
>>> >
>>> >Target is ARM EABI, command line generated via GCC:
>>> >
>>> >arm-rtems4.11-ld -dc -dp -N -o b-atsamv/app.exe
>>> >/opt/rtems-4.12/arm-rtems4.12/atsamv/lib/start.o
>>> /opt/rtems-4.12/lib64/gcc/arm-rtems4.12/6.1.1/thumb/cortex-m7/fpv5-d16/hard/crti.o
>>> /opt/rtems-4.12/lib64/gcc/arm-rtems4.12/6.1.1/thumb/cortex-m7/fpv5-d16/hard/crtbegin.o
>>>
>>> >-e _start
>>> >-L/opt/rtems-4.12/lib64/gcc/arm-rtems4.12/6.1.1/thumb/cortex-m7/fpv5-d16/hard
>>> -L/opt/rtems-4.12/lib64/gcc/arm-rtems4.12/6.1.1/../../../../arm-rtems4.12/lib/thumb/cortex-m7/fpv5-d16/hard
>>>
>>> >-L/opt/rtems-4.12/arm-rtems4.12/atsamv/lib
>>> >-L/opt/rtems-4.12/lib64/gcc/arm-rtems4.12/6.1.1
>>> >-L/opt/rtems-4.12/lib64/gcc/arm-rtems4.12/6.1.1/../../../../arm-rtems4.12/lib
>>>
>>> >--gc-sections -Map b-atsamv/app.map b-atsamv/init.o
>>> >b-atsamv/dev/cfi/cfi_core.o b-atsamv/atsam_flash.o
>>> >b-atsamv/test-file-system.o -ljffs2 --start-group -lgcc --start-group
>>> >-lrtemsbsp -lrtemscpu -latomic -lc -lgcc --end-group --end-group
>>> /opt/rtems-4.12/lib64/gcc/arm-rtems4.12/6.1.1/thumb/cortex-m7/fpv5-d16/hard/crtend.o
>>> /opt/rtems-4.12/lib64/gcc/arm-rtems4.12/6.1.1/thumb/cortex-m7/fpv5-d16/hard/crtn.o
>>>
>>> >-T linkcmds.sdram
>> I don't see anything odd there, but I can't reproduce the global to
>> local change with a simple testcase. All of my linker script symbols
>> are global.
>
> Ok, I try to create a simple test case.
>
--
Sebastian Huber, embedded brains GmbH
Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone : +49 89 189 47 41-16
Fax : +49 89 189 47 41-09
E-Mail : sebastian.huber@embedded-brains.de
PGP : Public key available on request.
Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.
More information about the Binutils
mailing list