Skip to content

llvm-readelf "invalid PT_DYNAMIC size" for RISC-V after getrandom() vDSO implementation #2093

Closed

Description

@nathanchance

After commit 89079520cef6 ("RISC-V: vDSO: Wire up getrandom() vDSO implementation") in -next, I see a warning from llvm-readelf with ARCH=riscv allmodconfig. As of next-20250527, a tangential fix is needed for LLVM=1 to work.

$ make -skj"$(nproc)" ARCH=riscv LLVM=1 mrproper allmodconfig arch/riscv/kernel/vdso/
llvm-readelf: warning: 'arch/riscv/kernel/vdso/vdso.so.dbg': invalid PT_DYNAMIC size (0xb8)
llvm-readelf: warning: 'arch/riscv/kernel/vdso/vdso.so.dbg': PT_DYNAMIC dynamic table is invalid: SHT_DYNAMIC will be used

I was able to narrow this down to CONFIG_INIT_STACK_ALL_PATTERN (which enables -ftrivial-auto-var-init=pattern) on top of defconfig, which is different from the default of CONFIG_INIT_STACK_ALL_ZERO:

$ printf 'CONFIG_%s\n' INIT_STACK_ALL_{PATTERN=y,ZERO=n} >kernel/configs/init_stack_pattern.config

$ make -skj"$(nproc)" ARCH=riscv LLVM=1 clean defconfig init_stack_pattern.config arch/riscv/kernel/vdso/
llvm-readelf: warning: 'arch/riscv/kernel/vdso/vdso.so.dbg': invalid PT_DYNAMIC size (0xb8)
llvm-readelf: warning: 'arch/riscv/kernel/vdso/vdso.so.dbg': PT_DYNAMIC dynamic table is invalid: SHT_DYNAMIC will be used

@MaskRay have you ever seen anything like this? There are a few times this warning has shown up before but I have never seen it until this point. Are there any recommendations for debugging this?

Activity

  1. added
    [ARCH] risc-v
    [BUG] linux-next
    [TOOL] llvm-readelf
    on May 27, 2025
  2. nathanchance commented on May 27, 2025

    @nathanchance
    MemberAuthor

    Also, this hack hides the issue for me:

    diff --git a/arch/riscv/kernel/vdso/Makefile b/arch/riscv/kernel/vdso/Makefile
    index 8d12f5646eb5..9b3d107192e0 100644
    --- a/arch/riscv/kernel/vdso/Makefile
    +++ b/arch/riscv/kernel/vdso/Makefile
    @@ -33,7 +33,7 @@ ifneq ($(c-gettimeofday-y),)
     endif
    
     ifneq ($(c-getrandom-y),)
    -  CFLAGS_getrandom.o += -fPIC -include $(c-getrandom-y)
    +  CFLAGS_getrandom.o += -fPIC -include $(c-getrandom-y) -ftrivial-auto-var-init=uninitialized
     endif
    
     CFLAGS_hwprobe.o += -fPIC
  3. MaskRay commented on May 29, 2025

    @MaskRay
    Member

    This diagnostic specifies that the .dynamic section is invalid, probably out-of-bounds sh_offset or sh_size%sh_entsize!=0.

    However, I cannot reproduce the issue at commit 90b83ef

    commit 90b83efa6701656e02c86e7df2cb1765ea602d07 (HEAD -> master, origin/master, origin/HEAD)
    Author: Linus Torvalds <torvalds@linux-foundation.org>
    Date:   Wed May 28 15:52:42 2025
    
        Merge tag 'bpf-next-6.16' of git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next
    
    % PATH=/tmp/Rel/bin:$PATH make O=/tmp/linux/rv-llvm ARCH=riscv LLVM=1 -j60 ARCH=riscv LLVM=1 clean defconfig init_stack_pattern.config arch/riscv/kernel/vdso/
    ...
    % /tmp/Rel/bin/llvm-readelf -Sd /tmp/linux/rv-llvm/arch/riscv/kernel/vdso/vdso.so.dbg
    There are 17 section headers, starting at offset 0x15b8:
    
    Section Headers:
      [Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al
      [ 0]                   NULL            0000000000000000 000000 000000 00      0   0  0
      [ 1] .hash             HASH            0000000000000158 000158 000048 04   A  3   0  4
      [ 2] .gnu.hash         GNU_HASH        00000000000001a0 0001a0 000040 00   A  3   0  8
      [ 3] .dynsym           DYNSYM          00000000000001e0 0001e0 0000c0 18   A  4   1  8
      [ 4] .dynstr           STRTAB          00000000000002a0 0002a0 0000a4 00   A  0   0  1
      [ 5] .gnu.version      VERSYM          0000000000000344 000344 000010 02   A  3   0  2
      [ 6] .gnu.version_d    VERDEF          0000000000000354 000354 000038 00   A  4   2  4
      [ 7] .dynamic          DYNAMIC         0000000000000390 000390 0000b0 10  WA  4   0  8
      [ 8] .note             NOTE            0000000000000440 000440 00003c 00   A  0   0  4
      [ 9] .eh_frame_hdr     PROGBITS        000000000000047c 00047c 00002c 00   A  0   0  4
      [10] .eh_frame         PROGBITS        00000000000004a8 0004a8 000084 00   A  0   0  8
      [11] .text             PROGBITS        0000000000000530 000530 000632 00  AX  0   0  4
      [12] .riscv.attributes RISCV_ATTRIBUTES 0000000000000000 000b62 0000d0 00      0   0  1
      [13] .comment          PROGBITS        0000000000000000 000c32 00002c 01  MS  0   0  1
      [14] .symtab           SYMTAB          0000000000000000 000c60 000780 18     16  77  8
      [15] .shstrtab         STRTAB          0000000000000000 0013e0 000099 00      0   0  1
      [16] .strtab           STRTAB          0000000000000000 001479 000139 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)
    Dynamic section at offset 0x390 contains 11 entries:
      Tag                Type        Name/Value
      0x000000000000000e (SONAME)    Library soname: [linux-vdso.so.1]
      0x0000000000000006 (SYMTAB)    0x1e0
      0x000000000000000b (SYMENT)    24 (bytes)
      0x0000000000000005 (STRTAB)    0x2a0
      0x000000000000000a (STRSZ)     164 (bytes)
      0x000000006ffffef5 (GNU_HASH)  0x1a0
      0x0000000000000004 (HASH)      0x158
      0x000000006ffffff0 (VERSYM)    0x344
      0x000000006ffffffc (VERDEF)    0x354
      0x000000006ffffffd (VERDEFNUM) 2
      0x0000000000000000 (NULL)      0x0
    
  4. nathanchance commented on May 29, 2025

    @nathanchance
    MemberAuthor

    You'll need to merge the pending RISC-V tree into mainline to see this.

    $ git cite
    90b83efa6701 ("Merge tag 'bpf-next-6.16' of git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next")
    
    $ git pull --no-edit https://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux.git/ for-next
    
    $ curl -LSs https://lore.kernel.org/all/20250423-riscv-fix-compat_vdso-lld-v2-1-b7bbbc244501@kernel.org/raw | git apply -3
    
    $ printf 'CONFIG_%s\n' INIT_STACK_ALL_{PATTERN=y,ZERO=n} >kernel/configs/init_stack_pattern.config
    
    $ make -skj"$(nproc)" ARCH=riscv LLVM=1 clean defconfig init_stack_pattern.config arch/riscv/kernel/vdso/
    llvm-readelf: warning: 'arch/riscv/kernel/vdso/vdso.so.dbg': invalid PT_DYNAMIC size (0xb8)
    llvm-readelf: warning: 'arch/riscv/kernel/vdso/vdso.so.dbg': PT_DYNAMIC dynamic table is invalid: SHT_DYNAMIC will be used
    
    $ llvm-readelf -Sd arch/riscv/kernel/vdso/vdso.so.dbg
    llvm-readelf: warning: 'arch/riscv/kernel/vdso/vdso.so.dbg': invalid PT_DYNAMIC size (0xb8)
    llvm-readelf: warning: 'arch/riscv/kernel/vdso/vdso.so.dbg': PT_DYNAMIC dynamic table is invalid: SHT_DYNAMIC will be used
    There are 18 section headers, starting at offset 0x2690:
    
    Section Headers:
      [Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al
      [ 0]                   NULL            0000000000000000 000000 000000 00      0   0  0
      [ 1] .hash             HASH            0000000000000158 000158 000050 04   A  3   0  4
      [ 2] .gnu.hash         GNU_HASH        00000000000001a8 0001a8 000048 00   A  3   0  8
      [ 3] .dynsym           DYNSYM          00000000000001f0 0001f0 0000d8 18   A  4   1  8
      [ 4] .dynstr           STRTAB          00000000000002c8 0002c8 0000b5 00   A  0   0  1
      [ 5] .gnu.version      VERSYM          000000000000037e 00037e 000012 02   A  3   0  2
      [ 6] .gnu.version_d    VERDEF          0000000000000390 000390 000038 00   A  4   2  4
      [ 7] .dynamic          DYNAMIC         00000000000003c8 0003c8 0000b0 10  WA  4   0  8
      [ 8] .rodata           PROGBITS        0000000000000478 000478 000008 00 WAM  0   0  8
      [ 9] .note             NOTE            0000000000000480 000480 00003c 00   A  0   0  4
      [10] .eh_frame_hdr     PROGBITS        00000000000004bc 0004bc 00002c 00   A  0   0  4
      [11] .eh_frame         PROGBITS        00000000000004e8 0004e8 000084 00   A  0   0  8
      [12] .text             PROGBITS        0000000000000570 000570 000c82 00  AX  0   0  4
      [13] .riscv.attributes RISCV_ATTRIBUTES 0000000000000000 0011f2 0000c2 00      0   0  1
      [14] .comment          PROGBITS        0000000000000000 0012b4 0000f1 01  MS  0   0  1
      [15] .symtab           SYMTAB          0000000000000000 0013a8 0010b0 18     17 174  8
      [16] .shstrtab         STRTAB          0000000000000000 002458 0000a1 00      0   0  1
      [17] .strtab           STRTAB          0000000000000000 0024f9 000197 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)
    Dynamic section at offset 0x3c8 contains 11 entries:
      Tag                Type        Name/Value
      0x000000000000000e (SONAME)    Library soname: [linux-vdso.so.1]
      0x0000000000000006 (SYMTAB)    0x1f0
      0x000000000000000b (SYMENT)    24 (bytes)
      0x0000000000000005 (STRTAB)    0x2c8
      0x000000000000000a (STRSZ)     181 (bytes)
      0x000000006ffffef5 (GNU_HASH)  0x1a8
      0x0000000000000004 (HASH)      0x158
      0x000000006ffffff0 (VERSYM)    0x37e
      0x000000006ffffffc (VERDEF)    0x390
      0x000000006ffffffd (VERDEFNUM) 2
      0x0000000000000000 (NULL)      0x0
    
  5. MaskRay commented on May 31, 2025

    @MaskRay
    Member

    Thanks for the detailed reproduce instructions! My git-fu is not that good. As I got a merge conflict when I invoked git pull, I went with the old way: git remote add riscv https://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux.git ...

    Here is a commit that resolves the issue. The issue arose since 8f8c1ff (in 2023)
    ("riscv: vdso.lds.S: remove hardcoded 0x800 .text start addr"), which placed .rodata directly after .dynamic by removing .eh_frame.

    This patch resolves the issue: https://github.com/MaskRay/linux/commits/riscv-vdso If it looks good, perhaps you could help me send it to the RISC-V tree? Thanks!

  6. nathanchance commented on Jun 2, 2025

    @nathanchance
    MemberAuthor

    Looks good to me! If you have not tried b4 for sending kernel changes, I would recommend giving it a try. Here is how I would do it (this is distilled down from that documentation):

    # I usually base off of the maintainer's tree, you can use your remote and adjust FETCH_HEAD below
    $ git fetch https://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux.git/ for-next
    
    # 'b4 prep' creates a fresh branch to work off of, which allows you to reuse your
    # cover letter (including your To: and Cc:) across various revisions
    $ b4 prep -f FETCH_HEAD -n riscv-vdso-fix-rodata-segment
    
    # cherry-pick your local commit to the new b4/ branch
    # normally you would create your series here
    
    # '--auto-to-cc' automatically runs scripts/get_maintainer.pl
    # '--check' automatically runs scripts/checkpatch.pl
    $ b4 prep --auto-to-cc --check
    
    # '--edit-cover' allows you to edit the cover letter. Since this is a single patch,
    # you do not need to add any content here (just delete the commented lines and the
    # signoff line, adjust the title to something for you locally, leaving the previously
    # added To: and Cc: lines alone). For series that include multiple patches, you would
    # add some executive summary above the To: and Cc: lines.
    $ b4 prep --edit-cover
    
    # Check that the patch and recipients generally looks okay
    $ b4 send --dry-run
    
    # Actually send it, using your .gitconfig values if available
    $ b4 send
  7. MaskRay commented on Jun 3, 2025

    @MaskRay
    Member

    Thanks for the detailed instructions! This is the first time I used b4 send. OK, here is the message: https://lore.kernel.org/linux-riscv/20250602-riscv-vdso-v1-1-0620cf63cff0@maskray.me/T/#u

  8. added
    [PATCH] Submitted
    on Jun 3, 2025
  9. 6 remaining items

  10. added
    [PATCH] Accepted
    on Jun 18, 2025
  11. added
    [FIXED][LINUX] 6.16
    and removed
    [PATCH] Accepted
    on Aug 13, 2025
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

    [ARCH] risc-v[BUG] linux[FIXED][LINUX] 6.16[TOOL] llvm-readelf

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions