Skip to content

SHT_CREL is unsupported for sh_info #640

Description

@Amichaxx

Describe the bug

patchelf seems to miss updating sh_info for SHT_CREL sections when it reorders sections.

  [ 6] .rodata           PROGBITS        000000000162f100 162f100 f946c8 00 AMS  0   0 256
  [10] .text             PROGBITS        0000000002670000 2660000 dc80f2c 00 AXR  0   0 65536
  [16] .tdata            PROGBITS        0000000010307100 102e7100 0000c8 00 WAT  0   0 32
  [30] .crel.text        CREL            0000000000000000 10df0008 1efa4f2 00   I 41  16  8
  [37] .crel.rodata      CREL            0000000000000000 142a6c58 004d69 00   I 41  12  8
  [38] .crel.note.crashpad.info CREL     0000000000000000 142ab9c1 000008 01   I 41   3  1
  [40] .rela.tdata       RELA            0000000000000000 142abdc0 000018 18   I 41  16  8
  [48] .note.crashpad.info NOTE          000000001c931ff8 1c931ff8 000020 00   A  0   0  4

For example, .crel.text points to .tdata, but it should point to .text.

This patch is motivated by llvm/BOLT. We are unable to BOLT a (downstream) Chromium binary due to this issue.

Steps To Reproduce

I have checked and don't believe the usual nixpkgs Chromium build uses CREL, so here is a minimal repro:

cat > crel.s <<'EOF'
.section .note.creltest,"a",%note
.balign 4
target:
  .word 0

.text
.globl _start
_start:
  adrp x0, target
  add x0, x0, :lo12:target
  ret
EOF

clang -target aarch64-linux-gnu \
  -Wa,--allow-experimental-crel,--crel \
  -fuse-ld=lld \
  -nostdlib \
  -Wl,--emit-relocs \
  -Wl,-rpath,/x \
  crel.s -o repro

Expected behavior
sh_info should still point to the section being relocated after patchelf rewrites.

Version

patchelf 0.15.2

Additional context

A local patch updates sortShdrs() to add SHT_CREL, which mirrors handling for SHT_REL and SHT_RELA. Overlaying this over patchelf appears to solve the issue. Happy to, in future, post a patch if this makes sense to the community.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions