[lld] [lld][AArch64][ELF][PAC] Support `.relr.auth.dyn` section (PR #87635)

via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 7 11:25:36 PDT 2024


zeroomega wrote:

> > We started seeing an lld relocation issue, and I bisected to this commit.
> > ```
> > [164519/322444](64) SOLINK arm64-shared/libmagma_shared.so
> > FAILED: arm64-shared/libmagma_shared.so arm64-shared/lib.unstripped/libmagma_shared.so arm64-shared/libmagma_shared.so.build-id.stamp arm64-shared/libmagma_shared.ifs arm64-shared/link_stub/libmagma_shared.so 
> > mkdir -p arm64-shared/lib.unstripped &&  ../../prebuilt/third_party/clang/custom/bin/clang++ -shared -Wl,-soname="libmagma_shared.so" -Wl,--whole-archive arm64-shared/obj/src/graphics/lib/magma/src/libmagma/libmagma_client.a -Wl,--no-whole-archive -fcolor-diagnostics -Wl,--color-diagnostics -fcrash-diagnostics-dir=clang-crashreports -fcrash-diagnostics=all -gen-reproducer=error --sysroot=arm64-shared/gen/zircon/public/sysroot/cpp --target=aarch64-unknown-fuchsia -ffuchsia-api-level=4293918720 -march=armv8-a+simd+crc+crypto -mtune=generic -ffile-compilation-dir=. -no-canonical-prefixes -fomit-frame-pointer -fdata-sections -ffunction-sections -Wl,--gc-sections -Os -Wl,-O2 -flto -Wl,-mllvm,-wholeprogramdevirt-branch-funnel-threshold=0 -ffat-lto-objects -g3 -grecord-gcc-switches -gdwarf-5 -gz=zstd -fno-exceptions -fno-rtti -Wl,--icf=all -fPIC -Wl,--no-undefined -Lgen/zircon/system/ulib/c/c.aarch64 -L../../build/config/zircon/libc-dummy -o "arm64-shared/lib.unstripped/libmagma_shared.so" -Wl,--dependency-file="arm64-shared/libmagma_shared.so.d" -Wl,--Map="arm64-shared/lib.unstripped/libmagma_shared.so.map" "@arm64-shared/libmagma_shared.so.rsp"  gen/zircon/system/ulib/c/c.aarch64/libc.so && ../../prebuilt/third_party/clang/custom/bin/llvm-objcopy --strip-all "arm64-shared/lib.unstripped/libmagma_shared.so" "arm64-shared/libmagma_shared.so" && ../../prebuilt/tools/buildidtool/linux-x64/buildidtool -build-id-dir .build-id -stamp "arm64-shared/libmagma_shared.so.build-id.stamp" -entry "=arm64-shared/libmagma_shared.so" -entry ".debug=arm64-shared/lib.unstripped/libmagma_shared.so" &&  ../../prebuilt/third_party/clang/custom/bin/llvm-ifs --write-if-changed --output-ifs=arm64-shared/libmagma_shared.ifs --output-elf=arm64-shared/link_stub/libmagma_shared.so arm64-shared/lib.unstripped/libmagma_shared.so
> > ld.lld: error: arm64-shared/obj/src/graphics/lib/magma/src/libmagma/libmagma_client.a(magma_client.o): relocation section (index 44207) has invalid sh_info (0)
> > clang++: error: ld.lld command failed with exit code 1 (use -v to see invocation)
> > ```
> > 
> > 
> >     
> >       
> >     
> > 
> >       
> >     
> > 
> >     
> >   
> > [luci-milo.appspot.com/ui/p/fuchsia/builders/ci/clang_toolchain.ci.core.arm64-release/b8746515880088952657/overview](https://luci-milo.appspot.com/ui/p/fuchsia/builders/ci/clang_toolchain.ci.core.arm64-release/b8746515880088952657/overview)
> > This is just heads up, and I'll try to come up with a small reproducer. I'm just posting early in case you have any idea.
> 
> @gulfemsavrun With limited information, I suspect the root cause is something else. The lld error is to disallow a relocation section with an invalid target . You can run `llvm-readelf -S` on the relocatable file and figure out how it is built.

I did a few more testing yesterday and I can comfirm, with this change, lld generated an object file with an empty REL section with `sh_info` set to 0. This object file later triggered the lld error @gulfemsavrun reported.

Without this change:

```
➜  default git:(1f0f5e6ffac) ✗ /usr/local/google/home/haowei/SRC/clang/clang_revert/bin/clang++ -o user.basic_arm64/obj/zircon/system/ulib/c/string/strlen.link.o.debug -r -static -Wl,--build-id=none -Wl,--no-eh-frame-hdr -Wl,--undefined=strlen -Wl,--undefined=__libc_strlen -Wl,--undefined=__asan_strlen -Wl,--undefined=__hwasan_strlen -Wno-unused-command-line-argument -g3 -grecord-gcc-switches -gdwarf-5 -gz=zstd -fno-omit-frame-pointer -momit-leaf-frame-pointer -fdata-sections -ffunction-sections -Wl,--gc-sections -O2 -fno-exceptions -fno-rtti -ffile-compilation-dir=. -no-canonical-prefixes -fuse-ld=lld -Wl,-z,relro --target=aarch64-fuchsia -march=armv8-a+simd+crc+crypto -mtune=generic -fcolor-diagnostics -Wl,--color-diagnostics -fcrash-diagnostics-dir=clang-crashreports -fcrash-diagnostics=all -ffuchsia-api-level=4293918720 -nostartfiles -nolibc -nostdlib++ -Wl,--build-id=none -Wl,--no-eh-frame-hdr -Wl,--no-dynamic-linker -nostartfiles -nolibc -static-libstdc++ -L../../build/config/zircon/libc++-stub -Wl,--no-undefined -L../../build/config/zircon/libc-dummy -Lgen/ifs-as-needed -Wl,--dependency-file=user.basic_arm64/obj/zircon/system/ulib/c/string/strlen.link.o.d -Wl,-Map,user.basic_arm64/obj/zircon/system/ulib/c/string/strlen.link.o.map -Wl,--start-group '@user.basic_arm64/obj/zircon/system/ulib/c/string/strlen.link.o.rsp' -lc++ -Wl,--end-group
➜  default git:(1f0f5e6ffac) ✗ ../../prebuilt/third_party/clang/linux-x64/bin/llvm-readelf -S user.basic_arm64/obj/zircon/system/ulib/c/string/strlen.link.o.debug
There are 20 section headers, starting at offset 0x1020:

Section Headers:
  [Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            0000000000000000 000000 000000 00      0   0  0
  [ 1] .text.strlen      PROGBITS        0000000000000000 000040 00002c 00  AX  0   0  4
  [ 2] .debug_loclists   PROGBITS        0000000000000000 00006c 000054 00      0   0  1
  [ 3] .debug_abbrev     PROGBITS        0000000000000000 0000c0 0000ab 00   C  0   0  1
  [ 4] .debug_info       PROGBITS        0000000000000000 00016b 0000a5 00   C  0   0  1
  [ 5] .rela.debug_info  RELA            0000000000000000 000210 000078 18   I 17   4  8
  [ 6] .debug_str_offsets PROGBITS       0000000000000000 000288 00002d 00   C  0   0  1
  [ 7] .rela.debug_str_offsets RELA      0000000000000000 0002b8 000180 18   I 17   6  8
  [ 8] .debug_str        PROGBITS        0000000000000000 000438 000515 01 MSC  0   0  1
  [ 9] .debug_addr       PROGBITS        0000000000000000 00094d 000010 00      0   0  1
  [10] .rela.debug_addr  RELA            0000000000000000 000960 000018 18   I 17   9  8
  [11] .comment          PROGBITS        0000000000000000 000978 000077 01  MS  0   0  1
  [12] .debug_line       PROGBITS        0000000000000000 0009ef 0000b5 00      0   0  1
  [13] .rela.debug_line  RELA            0000000000000000 000aa8 0000a8 18   I 17  12  8
  [14] .debug_line_str   PROGBITS        0000000000000000 000b50 000090 01 MSC  0   0  1
  [15] .llvm_addrsig     LLVM_ADDRSIG    0000000000000000 000be0 000001 00   E  0   0  1
  [16] .note.GNU-stack   PROGBITS        0000000000000000 000be1 000000 00      0   0  1
  [17] .symtab           SYMTAB          0000000000000000 000be8 0002a0 18     19  23  8
  [18] .shstrtab         STRTAB          0000000000000000 000e88 00010a 00      0   0  1
  [19] .strtab           STRTAB          0000000000000000 000f92 00008e 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
  L (link order), O (extra OS processing required), G (group), T (TLS),
  C (compressed), x (unknown), o (OS specific), E (exclude),
  R (retain), p (processor specific)

```

With this change:

```
➜  default git:(1f0f5e6ffac) ✗ /usr/local/google/home/haowei/SRC/clang/clang_git_af57ad6536c7df19e6df7217d9d976067fdaf882/bin/clang++ -o user.basic_arm64/obj/zircon/system/ulib/c/string/strlen.link.o.debug -r -static -Wl,--build-id=none -Wl,--no-eh-frame-hdr -Wl,--undefined=strlen -Wl,--undefined=__libc_strlen -Wl,--undefined=__asan_strlen -Wl,--undefined=__hwasan_strlen -Wno-unused-command-line-argument -g3 -grecord-gcc-switches -gdwarf-5 -gz=zstd -fno-omit-frame-pointer -momit-leaf-frame-pointer -fdata-sections -ffunction-sections -Wl,--gc-sections -O2 -fno-exceptions -fno-rtti -ffile-compilation-dir=. -no-canonical-prefixes -fuse-ld=lld -Wl,-z,relro --target=aarch64-fuchsia -march=armv8-a+simd+crc+crypto -mtune=generic -fcolor-diagnostics -Wl,--color-diagnostics -fcrash-diagnostics-dir=clang-crashreports -fcrash-diagnostics=all -ffuchsia-api-level=4293918720 -nostartfiles -nolibc -nostdlib++ -Wl,--build-id=none -Wl,--no-eh-frame-hdr -Wl,--no-dynamic-linker -nostartfiles -nolibc -static-libstdc++ -L../../build/config/zircon/libc++-stub -Wl,--no-undefined -L../../build/config/zircon/libc-dummy -Lgen/ifs-as-needed -Wl,--dependency-file=user.basic_arm64/obj/zircon/system/ulib/c/string/strlen.link.o.d -Wl,-Map,user.basic_arm64/obj/zircon/system/ulib/c/string/strlen.link.o.map -Wl,--start-group '@user.basic_arm64/obj/zircon/system/ulib/c/string/strlen.link.o.rsp' -lc++ -Wl,--end-group
➜  default git:(1f0f5e6ffac) ✗ ../../prebuilt/third_party/clang/linux-x64/bin/llvm-readelf -S user.basic_arm64/obj/zircon/system/ulib/c/string/strlen.link.o.debug
There are 21 section headers, starting at offset 0x1078:

Section Headers:
  [Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            0000000000000000 000000 000000 00      0   0  0
  [ 1] .text.strlen      PROGBITS        0000000000000000 000040 00002c 00  AX  0   0  4
  [ 2] .debug_loclists   PROGBITS        0000000000000000 000070 00006c 00   C  0   0  1
  [ 3] .debug_abbrev     PROGBITS        0000000000000000 0000dc 0000ab 00   C  0   0  1
  [ 4] .debug_info       PROGBITS        0000000000000000 000187 0000a5 00   C  0   0  1
  [ 5] .rela.debug_info  RELA            0000000000000000 000230 000078 18   I 18   4  8
  [ 6] .debug_str_offsets PROGBITS       0000000000000000 0002a8 00002d 00   C  0   0  1
  [ 7] .rela.debug_str_offsets RELA      0000000000000000 0002d8 000180 18   I 18   6  8
  [ 8] .debug_str        PROGBITS        0000000000000000 000458 000515 01 MSC  0   0  1
  [ 9] .debug_addr       PROGBITS        0000000000000000 00096d 000031 00   C  0   0  1
  [10] .rela.debug_addr  RELA            0000000000000000 0009a0 000018 18   I 18   9  8
  [11] .comment          PROGBITS        0000000000000000 0009b8 000077 01  MS  0   0  1
  [12] .debug_line       PROGBITS        0000000000000000 000a2f 0000bb 00   C  0   0  1
  [13] .rela.debug_line  RELA            0000000000000000 000af0 0000a8 18   I 18  12  8
  [14] .debug_line_str   PROGBITS        0000000000000000 000b98 000090 01 MSC  0   0  1
  [15] .llvm_addrsig     LLVM_ADDRSIG    0000000000000000 000c28 000001 00   E  0   0  1
  [16] .rel.dyn          REL             0000000000000000 000070 000000 10   A  0   0  8
  [17] .note.GNU-stack   PROGBITS        0000000000000000 000c29 000000 00      0   0  1
  [18] .symtab           SYMTAB          0000000000000000 000c30 0002a0 18     20  23  8
  [19] .shstrtab         STRTAB          0000000000000000 000ed0 000113 00      0   0  1
  [20] .strtab           STRTAB          0000000000000000 000fe3 00008e 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
  L (link order), O (extra OS processing required), G (group), T (TLS),
  C (compressed), x (unknown), o (OS specific), E (exclude),
  R (retain), p (processor specific)
➜  default git:(1f0f5e6ffac) ✗
```

You can see index 16, `.rel.dyn` section is empty with `sh_info(0)`.
It will be a bit difficult to construct an end to end reproducer but I will have a try. 

https://github.com/llvm/llvm-project/pull/87635


More information about the llvm-commits mailing list