Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

llvm-strip fail on cgo code with error: SHT_STRTAB string table section [index 4] is non-null terminated #53999

Open
kraj opened this issue Feb 22, 2022 · 7 comments

Comments

@kraj
Copy link
Contributor

kraj commented Feb 22, 2022

Attached example is causing strip failures

$ mips-yoe-linux-llvm-strip --remove-section=.note --remove-section=.comment go-helloworld
$ mips-yoe-linux-llvm-strip --remove-section=.note --remove-section=.comment go-helloworld
./recipe-sysroot-native/usr/bin/mips-yoe-linux/mips-yoe-linux-llvm-strip: error: SHT_STRTAB string table section [index 4] is non-null terminated

you have to run the strip twice to get this error. However when I use GNU strip first time then it works fine during second time.
so it seems llvm-strip is mutilating the binary during first strip operation somehow.
go-helloworld.tar.gz

@llvmbot
Copy link
Collaborator

llvmbot commented Feb 22, 2022

@llvm/issue-subscribers-tools-llvm-objcopy-strip

@llvmbot
Copy link
Collaborator

llvmbot commented Feb 22, 2022

@llvm/issue-subscribers-backend-mips

@berolinux
Copy link

berolinux commented Aug 1, 2022

This is platform independent and seems to happen with anything built by go.

$ cat test.go
package main
import "fmt"
func main() {
        fmt.Println("hello world")
}
$ go build test.go
$ llvm-strip test
$ llvm-strip test
llvm-strip: error: SHT_STRTAB string table section [index 3] is non-null terminated

readelf -a after the first llvm-strip shows section names getting corrupted (first 3 bytes chopped off). Probably the size of a remaining section is miscalculated, causing the first bytes of the succeeding section to end up in the old section.

Section Headers:
  [Nr] Name              Type             Address           Offset
       Size              EntSize          Flags  Link  Info  Align
  [ 0]                   NULL             0000000000000000  00000000
       0000000000000000  0000000000000000           0     0     0
  [ 1] .text             PROGBITS         0000000000401000  00001000
       000000000007cfe7  0000000000000000  AX       0     0     32
  [ 2] typelink          PROGBITS         000000000047e000  0007e000
       00000000000350c4  0000000000000000   A       0     0     32
  [ 3] ldinfo            STRTAB           0000000000000000  000b30e0
       0000000000000081  0000000000000000           0     0     1
  [ 4] ss                PROGBITS         00000000004b3260  000b3260
       00000000000004c0  0000000000000000   A       0     0     32
  [ 5] zzer_extra_c[...] PROGBITS         00000000004b3720  000b3720
       0000000000000058  0000000000000000   A       0     0     32
  [ 6] id                PROGBITS         00000000004b3778  000b3778
       0000000000000000  0000000000000000   A       0     0     1
  [ 7] te.go.buildid     PROGBITS         00000000004b3780  000b3780
       0000000000053878  0000000000000000   A       0     0     32
  [ 8] a                 PROGBITS         0000000000507000  00107000
       0000000000000110  0000000000000000  WA       0     0     16
  [ 9] a                 PROGBITS         0000000000507120  00107120
       00000000000105e0  0000000000000000  WA       0     0     32
  [10]                   PROGBITS         0000000000517700  00117700
       00000000000077d0  0000000000000000  WA       0     0     32
  [11]                   NOBITS           000000000051eee0  0011eee0
       000000000002ef60  0000000000000000  WA       0     0     32
  [12] .noptrdata        NOBITS           000000000054de40  0014de40
       0000000000005188  0000000000000000  WA       0     0     32
  [13] _counters         NOTE             0000000000400f9c  00000f9c
       0000000000000064  0000000000000000   A       0     0     4

@berolinux
Copy link

Also happens with an even smaller test case:

package main
func main() {
        return
}

@agherzan
Copy link

agherzan commented Aug 1, 2022

For reference these are the section headers on the unstripped binary:

Section Headers:
  [Nr] Name              Type             Address           Offset
       Size              EntSize          Flags  Link  Info  Align
  [ 0]                   NULL             0000000000000000  00000000
       0000000000000000  0000000000000000           0     0     0
  [ 1] .text             PROGBITS         0000000000401000  00001000
       0000000000054210  0000000000000000  AX       0     0     32
  [ 2] .rodata           PROGBITS         0000000000456000  00056000
       00000000000225b7  0000000000000000   A       0     0     32
  [ 3] .shstrtab         STRTAB           0000000000000000  000785c0
       000000000000017a  0000000000000000           0     0     1
  [ 4] .typelink         PROGBITS         0000000000478740  00078740
       00000000000002b0  0000000000000000   A       0     0     32
  [ 5] .itablink         PROGBITS         00000000004789f0  000789f0
       0000000000000008  0000000000000000   A       0     0     8
  [ 6] .gosymtab         PROGBITS         00000000004789f8  000789f8
       0000000000000000  0000000000000000   A       0     0     1
  [ 7] .gopclntab        PROGBITS         0000000000478a00  00078a00
       000000000003b988  0000000000000000   A       0     0     32
  [ 8] .go.buildinfo     PROGBITS         00000000004b5000  000b5000
       0000000000000110  0000000000000000  WA       0     0     16
  [ 9] .noptrdata        PROGBITS         00000000004b5120  000b5120
       00000000000011a0  0000000000000000  WA       0     0     32
  [10] .data             PROGBITS         00000000004b62c0  000b62c0
       00000000000021f0  0000000000000000  WA       0     0     32
  [11] .bss              NOBITS           00000000004b84c0  000b84c0
       000000000002eb60  0000000000000000  WA       0     0     32
  [12] .noptrbss         NOBITS           00000000004e7020  000e7020
       0000000000005148  0000000000000000  WA       0     0     32
  [13] .zdebug_abbrev    PROGBITS         00000000004ed000  000b9000
       0000000000000127  0000000000000000           0     0     1
  [14] .zdebug_line      PROGBITS         00000000004ed127  000b9127
       000000000001365d  0000000000000000           0     0     1
  [15] .zdebug_frame     PROGBITS         0000000000500784  000cc784
       0000000000003c35  0000000000000000           0     0     1
  [16] .debug_gdb_s[...] PROGBITS         00000000005043b9  000d03b9
       0000000000000028  0000000000000000           0     0     1
  [17] .zdebug_info      PROGBITS         00000000005043e1  000d03e1
       0000000000022a50  0000000000000000           0     0     1
  [18] .zdebug_loc       PROGBITS         0000000000526e31  000f2e31
       0000000000012202  0000000000000000           0     0     1
  [19] .zdebug_ranges    PROGBITS         0000000000539033  00105033
       0000000000006611  0000000000000000           0     0     1
  [20] .note.go.buildid  NOTE             0000000000400f9c  00000f9c
       0000000000000064  0000000000000000   A       0     0     4
  [21] .symtab           SYMTAB           0000000000000000  0010b648
       00000000000078f0  0000000000000018          22    84     8
  [22] .strtab           STRTAB           0000000000000000  00112f38
       0000000000006edf  0000000000000000

Also, this doesn't seem to always reproduce on go projects:

^ Same go, same llvm, etc.

@agherzan
Copy link

agherzan commented Aug 1, 2022

After digging a bit more into this, it looks like the moving part is cgo.

package main

/*
void foo(void) {}
*/
import "C"

func main() {
    return
}

This would work as expected while commenting out the import would reproduce this issue.

doanac pushed a commit to lmp-mirrors/meta-virtualization that referenced this issue Aug 4, 2022
clang-based builds are still broken due to:
llvm/llvm-project#53999

Signed-off-by: Andrei Gherzan <andrei.gherzan@huawei.com>
Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com>
doanac pushed a commit to lmp-mirrors/meta-virtualization that referenced this issue Aug 4, 2022
clang-based builds are still broken due to:
llvm/llvm-project#53999

Signed-off-by: Andrei Gherzan <andrei.gherzan@huawei.com>
Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com>
doanac pushed a commit to lmp-mirrors/meta-virtualization that referenced this issue Aug 4, 2022
clang-based builds are still broken due to:
llvm/llvm-project#53999

Signed-off-by: Andrei Gherzan <andrei.gherzan@huawei.com>
Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com>
doanac pushed a commit to lmp-mirrors/meta-virtualization that referenced this issue Aug 4, 2022
clang-based builds are still broken due to:
llvm/llvm-project#53999

Signed-off-by: Andrei Gherzan <andrei.gherzan@huawei.com>
Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com>
@tru tru changed the title llvm-strip fails on mips error: SHT_STRTAB string table section [index 4] is non-null terminated llvm-strip fail on cgo code with error: SHT_STRTAB string table section [index 4] is non-null terminated Aug 31, 2022
jpuhlman pushed a commit to MontaVista-OpenSourceTechnology/meta-virtualization that referenced this issue Sep 6, 2022
Source: meta-virtualization
MR: 121049
Type: Integration
Disposition: Merged from meta-virtualization
ChangeID: cb9ed15
Description:

clang-based builds are still broken due to:
llvm/llvm-project#53999

Signed-off-by: Andrei Gherzan <andrei.gherzan@huawei.com>
Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com>
Signed-off-by: Jeremy A. Puhlman <jpuhlman@mvista.com>
jpuhlman pushed a commit to MontaVista-OpenSourceTechnology/meta-virtualization that referenced this issue Sep 6, 2022
Source: meta-virtualization
MR: 121049
Type: Integration
Disposition: Merged from meta-virtualization
ChangeID: 26a361a
Description:

clang-based builds are still broken due to:
llvm/llvm-project#53999

Signed-off-by: Andrei Gherzan <andrei.gherzan@huawei.com>
Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com>
Signed-off-by: Jeremy A. Puhlman <jpuhlman@mvista.com>
@emaste
Copy link
Member

emaste commented Apr 21, 2023

Issue also observed in FreeBSD's attempt to use LLVM binutils for the entire ports tree: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=270962

daregit pushed a commit to daregit/yocto-combined that referenced this issue May 22, 2024
clang-based builds are still broken due to:
llvm/llvm-project#53999

Signed-off-by: Andrei Gherzan <andrei.gherzan@huawei.com>
Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com>
daregit pushed a commit to daregit/yocto-combined that referenced this issue May 22, 2024
clang-based builds are still broken due to:
llvm/llvm-project#53999

Signed-off-by: Andrei Gherzan <andrei.gherzan@huawei.com>
Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com>
daregit pushed a commit to daregit/yocto-combined that referenced this issue May 22, 2024
clang-based builds are still broken due to:
llvm/llvm-project#53999

Signed-off-by: Andrei Gherzan <andrei.gherzan@huawei.com>
Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com>
daregit pushed a commit to daregit/yocto-combined that referenced this issue May 22, 2024
clang-based builds are still broken due to:
llvm/llvm-project#53999

Signed-off-by: Andrei Gherzan <andrei.gherzan@huawei.com>
Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants