On 2015-07-08, Les Cargill <
lcarg...@comcast.com> wrote:
> COMMONMDATA should be "fixed up" by the linker, not the compiler
> itself. "gcc -c ...." should generate unresolved references to
> the variables in COMMONDATA ( as viewable by objdump) , and
> you'll need linker-script-fu to get all that sorted out.
>
> You want to arrange your source code where everything in COMMONDATA
> is "extern...". As I recall, the linker for GNU affords
> locating as well; you'd absolutely locate COMMONDATA and
> not-absolutely locate everything else.
Either I am not explaining myself very well, or I am not understanding
the suggestions. When I tell gcc to compile a C file as
position-independent code, each access to global data is translated into
a series of instructions that is quite different from what I get when I
don't specify any position-independent flags. I wouldn't expect the
linker to be able to convert the first series of instructions into the
second. Here is an example:
$ cat pic.c
extern int var; /* Specifying the section here makes no difference. */
void test(void)
{
var = 2;
}
### Not position-independent
$ /usr/local/bin/arm-none-eabi-gcc -O1 -c pic.c
$ /usr/local/bin/arm-none-eabi-objdump -dS pic.o
pic.o: file format elf32-littlearm
Disassembly of section .text:
00000000 <test>:
0: e3a02002 mov r2, #2
4: e59f3004 ldr r3, [pc, #4] ; 10 <test+0x10>
8: e5832000 str r2, [r3]
c: e12fff1e bx lr
10: 00000000 .word 0x00000000
### position-independent
$ /usr/local/bin/arm-none-eabi-gcc -fPIC -O1 -c pic.c
$ /usr/local/bin/arm-none-eabi-objdump -dS pic.o
pic.o: file format elf32-littlearm
Disassembly of section .text:
00000000 <test>:
0: e59f3014 ldr r3, [pc, #20] ; 1c <test+0x1c>
4: e08f3003 add r3, pc, r3
8: e59f2010 ldr r2, [pc, #16] ; 20 <test+0x20>
c: e7933002 ldr r3, [r3, r2]
10: e3a02002 mov r2, #2
14: e5832000 str r2, [r3]
18: e12fff1e bx lr
1c: 00000010 .word 0x00000010
20: 00000000 .word 0x00000000
Are you expecting the linker to change the indirect access in the second
listing to something that looks like the first one, assuming I specify
the correct sections in the linker script and other C files? I have not
had any luck in getting this to happen.
If the answer is that gcc just doesn't support the behavior I'm looking
for, that is OK. I am not demanding a solution from the group :).
Thanks again,
Chris