|
| 1 | +# REQUIRES: x86 |
| 2 | +## -z pack-relative-relocs is a variant of --pack-dyn-relocs=relr: add |
| 3 | +## GLIBC_ABI_DT_RELR verneed if there is a verneed named "GLIBC_2.*". |
| 4 | + |
| 5 | +# RUN: rm -rf %t && split-file %s %t |
| 6 | +# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/a.s -o %t/a.o |
| 7 | +# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/libc.s -o %t/libc.o |
| 8 | +# RUN: ld.lld -shared --soname=libc.so.6 --version-script=%t/glibc.ver %t/libc.o -o %t/libc.so.6 |
| 9 | + |
| 10 | +# RUN: ld.lld -pie %t/a.o %t/libc.so.6 -z pack-relative-relocs -o %t/glibc 2>&1 | count 0 |
| 11 | +# RUN: llvm-readelf -r -V %t/glibc | FileCheck %s --check-prefix=GLIBC |
| 12 | +## Arbitrarily let -z pack-relative-relocs win. |
| 13 | +# RUN: ld.lld -pie %t/a.o %t/libc.so.6 -z pack-relative-relocs --pack-dyn-relocs=relr -o %t/glibc2 |
| 14 | +# RUN: cmp %t/glibc %t/glibc2 |
| 15 | + |
| 16 | +# GLIBC: Relocation section '.relr.dyn' at offset {{.*}} contains 1 entries: |
| 17 | +# GLIBC: Version needs section '.gnu.version_r' contains 1 entries: |
| 18 | +# GLIBC-NEXT: Addr: {{.*}} |
| 19 | +# GLIBC-NEXT: 0x0000: Version: 1 File: libc.so.6 Cnt: 2 |
| 20 | +# GLIBC-NEXT: 0x0010: Name: GLIBC_2.33 Flags: none Version: 2 |
| 21 | +# GLIBC-NEXT: 0x0020: Name: GLIBC_ABI_DT_RELR Flags: none Version: 3 |
| 22 | +# GLIBC-EMPTY: |
| 23 | + |
| 24 | +# RUN: ld.lld -pie %t/a.o %t/libc.so.6 -z pack-relative-relocs -z nopack-relative-relocs -o %t/notrelr 2>&1 | count 0 |
| 25 | +# RUN: llvm-readelf -r -V %t/notrelr | FileCheck %s --check-prefix=REGULAR |
| 26 | + |
| 27 | +# REGULAR-NOT: Relocation section '.relr.dyn' |
| 28 | +# REGULAR-NOT: Name: GLIBC_ABI_DT_RELR |
| 29 | + |
| 30 | +## soname is not "libc.so.*". Don't synthesize GLIBC_ABI_DT_RELR. In glibc, ld.so |
| 31 | +## doesn't define GLIBC_ABI_DT_RELR. libc.so itself should not reference GLIBC_ABI_DT_RELR. |
| 32 | +# RUN: ld.lld -shared --soname=ld-linux-x86-64.so.2 --version-script=%t/glibc.ver %t/libc.o -o %t/ld.so |
| 33 | +# RUN: ld.lld -pie %t/a.o %t/ld.so -z pack-relative-relocs -o %t/other 2>&1 | count 0 |
| 34 | +# RUN: llvm-readelf -r -V %t/other | FileCheck %s --check-prefix=NOTLIBC |
| 35 | + |
| 36 | +# NOTLIBC: Relocation section '.relr.dyn' at offset {{.*}} contains 1 entries: |
| 37 | +# NOTLIBC-NOT: Name: GLIBC_ABI_DT_RELR |
| 38 | + |
| 39 | +## There is no GLIBC_2.* verneed. Don't add GLIBC_ABI_DT_RELR verneed. |
| 40 | +# RUN: ld.lld -shared --soname=libc.so.6 --version-script=%t/other.ver %t/libc.o -o %t/libc.so.6 |
| 41 | +# RUN: ld.lld -pie %t/a.o %t/libc.so.6 -z pack-relative-relocs -o %t/other |
| 42 | +# RUN: llvm-readelf -r -V %t/other | FileCheck %s --check-prefix=NOTLIBC |
| 43 | + |
| 44 | +#--- a.s |
| 45 | +.globl _start |
| 46 | +_start: |
| 47 | + call stat |
| 48 | + |
| 49 | +.data |
| 50 | +.balign 8 |
| 51 | +.dc.a .data |
| 52 | + |
| 53 | +#--- libc.s |
| 54 | +.weak stat |
| 55 | +stat: |
| 56 | + |
| 57 | +#--- glibc.ver |
| 58 | +GLIBC_2.33 { |
| 59 | + stat; |
| 60 | +}; |
| 61 | + |
| 62 | +#--- other.ver |
| 63 | +GLIBC_3 { |
| 64 | + stat; |
| 65 | +}; |
0 commit comments