-
Notifications
You must be signed in to change notification settings - Fork 43
Open
Labels
Description
When a non-PIE dynamic executable is compiled with -O2, we get PC-relative relocations for data symbols defined in shared objects. Currently, ELD doesn't generate copy relocations for these cases, but it should.
Reproduction: For non-PIE case
#!/usr/bin/env bash
cat >1.c <<\EOF
extern int u;
int main() {
u = 11;
return u;
}
EOF
cat >2.c <<\EOF
int u=5;
EOF
clang -c 1.c -o 1.o -fno-pic -O2
readelf -r 1.o # Shows R_X86_64_PC32 against symbol 'u'
clang -c 2.c -o 2.o -fPIC
eld -shared -o libu.so 2.o
clang -fuse-ld=eld -o 1.eld.out 1.o libu.so -no-pie
readelf -r 1.eld.out # Currently does not have R_X86_64_COPY for uThere is an additional case where object built with -fno-pic -O2 that has PC-relative relocations is linked with -pie against a DSO. lld emit a copy relocation in this case as well
Reproduction: for PIE case
#!/usr/bin/env bash
cat >1.c <<\EOF
extern int u;
int main() {
u = 11;
return u;
}
EOF
cat >2.c <<\EOF
int u=5;
EOF
clang -c 1.c -o 1.o -fno-pic -O2
readelf -r 1.o # Shows R_X86_64_PC32 against symbol 'u'
clang -c 2.c -o 2.o -fPIC
eld -shared -o libu.so 2.o
clang -fuse-ld=eld -o 1.eld.out 1.o libu.so -pie
readelf -r 1.eld.out # Currently does not have R_X86_64_COPY for u