Skip to content

[x86_64] Support emission of Copy Relocations For PC-Relative Referenced Data Symbols #669

@BhoumikPatidar

Description

@BhoumikPatidar

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 u

There 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

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions