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

cmd/link: offset overlap for DWARF sections in elf headers #51939

Closed
thanm opened this issue Mar 25, 2022 · 4 comments
Closed

cmd/link: offset overlap for DWARF sections in elf headers #51939

thanm opened this issue Mar 25, 2022 · 4 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@thanm
Copy link
Contributor

thanm commented Mar 25, 2022

What version of Go are you using (go version)?

$ go version
go version devel go1.19-a10a209b23 Thu Mar 24 21:51:49 2022 +0000 linux/amd64

Does this issue reproduce with the latest release?

Only on tip (not a problem for 1.18).

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOOS="linux"

What did you do?

While debugging an unrelated test failure, I made a hack in my repo to disable the code in cmd/go that builds test binaries with "-s -w" (for speed). After I did this, all.bash would no longer pass, instead I saw failures in debug/elf. Failure looks like this:

$ go test -ldflags="-s=0 -w=0" debug/elf
--- FAIL: TestNoSectionOverlaps (0.00s)
    file_test.go:922: ld produced ELF with section .debug_line within .debug_abbrev: 0x26a000 <= 0x26a133..0x2ccf08 < 0x26a210
    file_test.go:922: ld produced ELF with section .debug_frame within .debug_line: 0x26a133 <= 0x29feef..0x2bdff3 < 0x2ccf08
    file_test.go:922: ld produced ELF with section .debug_gdb_scripts within .debug_line: 0x26a133 <= 0x2aa8ce..0x2aa8f3 < 0x2ccf08
    file_test.go:922: ld produced ELF with section .debug_gdb_scripts within .debug_frame: 0x29feef <= 0x2aa8ce..0x2aa8f3 < 0x2bdff3
    file_test.go:922: ld produced ELF with section .debug_info within .debug_line: 0x26a133 <= 0x2aa8f3..0x3922fc < 0x2ccf08
    file_test.go:922: ld produced ELF with section .debug_info within .debug_frame: 0x29feef <= 0x2aa8f3..0x3922fc < 0x2bdff3
    file_test.go:922: ld produced ELF with section .debug_loc within .debug_info: 0x2aa8f3 <= 0x307b8e..0x44b903 < 0x3922fc
    file_test.go:922: ld produced ELF with section .debug_ranges within .debug_info: 0x2aa8f3 <= 0x341e93..0x3ab283 < 0x3922fc
    file_test.go:922: ld produced ELF with section .debug_ranges within .debug_loc: 0x307b8e <= 0x341e93..0x3ab283 < 0x44b903
    file_test.go:922: ld produced ELF with section .symtab within .debug_info: 0x2aa8f3 <= 0x354f58..0x36bfe0 < 0x3922fc
    file_test.go:922: ld produced ELF with section .symtab within .debug_loc: 0x307b8e <= 0x354f58..0x36bfe0 < 0x44b903
    file_test.go:922: ld produced ELF with section .symtab within .debug_ranges: 0x341e93 <= 0x354f58..0x36bfe0 < 0x3ab283
    file_test.go:922: ld produced ELF with section .strtab within .debug_info: 0x2aa8f3 <= 0x36bfe0..0x382d8b < 0x3922fc
    file_test.go:922: ld produced ELF with section .strtab within .debug_loc: 0x307b8e <= 0x36bfe0..0x382d8b < 0x44b903
    file_test.go:922: ld produced ELF with section .strtab within .debug_ranges: 0x341e93 <= 0x36bfe0..0x382d8b < 0x3ab283
FAIL
FAIL	debug/elf	0.034s
FAIL

I did a git bisect on the problem, which pointed to this commit, reviewed at https://go-review.googlesource.com/c/go/+/380755.

@mengzhuo

@thanm thanm added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Mar 25, 2022
@mengzhuo mengzhuo self-assigned this Mar 25, 2022
@cherrymui
Copy link
Member

cherrymui commented Mar 25, 2022

It looks like the debug/elf package sets Section.Size to uncompressed size. Perhaps the test needs to be adjusted.

  • If we want to test that sections are not overlapped in the file, we probably should use FileSize instead of Size.
  • if we want to test that they are not overlapped in address space, we probably should not include unmapped sections (DWARF)

@mengzhuo
Copy link
Contributor

mengzhuo commented Mar 26, 2022

There are two issues needs to be fixed:

  1. debug/elf should skip overlap test if sections is unmapped.
  2. the DWARF sections do set Addr since elfshbits doesn't follow SHF_ALLOC.

@gopherbot
Copy link

gopherbot commented Mar 26, 2022

Change https://go.dev/cl/395919 mentions this issue: cmd/link: zero elf addr for debug sections

@gopherbot
Copy link

gopherbot commented Mar 26, 2022

Change https://go.dev/cl/395920 mentions this issue: debug/elf: skip Overlap test for unmapped sections

gopherbot pushed a commit that referenced this issue Mar 30, 2022
The Addr should be zero if SHF_ALLOC is not set.

Update #51939

Change-Id: I030f6243d05efabe6b9ebf558e9c0201f7922d23
Reviewed-on: https://go-review.googlesource.com/c/go/+/395919
Trust: mzh <mzh@golangcn.org>
Run-TryBot: mzh <mzh@golangcn.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants