-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a9503c5
Showing
9 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dwarf-relocation-golang-bug |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.PHONY: all test | ||
|
||
all: test | ||
|
||
testdata/repro: | ||
cd testdata && make | ||
|
||
dwarf-relocation-golang-bug: main.go | ||
go build | ||
|
||
test: testdata/repro dwarf-relocation-golang-bug | ||
@echo | ||
@echo "Running test" | ||
@./test.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
This is a standalone repro case for https://github.com/golang/go/issues/40879 | ||
|
||
* `testdata` contains logic to build an executable `testdata/repro` that: | ||
* has a `.rela.debug_ranges` section | ||
* has a DWARF DIE that uses DW_AT_ranges (to force this, I used a linker script to spread the code across 2 sections at different addresses) | ||
* `main.go` contains logic that prints the PC ranges of `testdata/repro` | ||
* `test.sh` will print the PC ranges using both the Go binary, and `llvm-dwarfdump`, to highlight the difference | ||
* `make` will compile all binaries and run `test.sh` | ||
|
||
Note: you need `llvm` installed (for `llvm-dwarfdump`). Alternatively you can change the test.sh script to use the regular `dwarfdump`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package main | ||
|
||
import ( | ||
"debug/elf" | ||
"fmt" | ||
"log" | ||
) | ||
|
||
func main() { | ||
file, err := elf.Open("testdata/repro") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer file.Close() | ||
|
||
dw, err := file.DWARF() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
reader := dw.Reader() | ||
|
||
// The first entry will be the (only) CU | ||
entry, err := reader.Next() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
// Read PC ranges from DIE | ||
ranges, err := dw.Ranges(entry) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
for i := range ranges { | ||
fmt.Printf("[0x%x, 0x%x)\n", ranges[i][0], ranges[i][1]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/bash -eu | ||
|
||
echo "Actual ranges:" | ||
llvm-dwarfdump testdata/repro --name=repro.c | grep -A2 DW_AT_ranges | tail -2 | sed 's/))/)/' | tr -d ' ' | ||
|
||
echo | ||
echo "Ranges derived from Golang's debug/elf + debug/dwarf" | ||
./dwarf-relocation-golang-bug | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
repro |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.PHONY: all | ||
|
||
repro: repro.c repro.ld | ||
# The following command will likely print a warning (about a missing -T option), which should be ignored. | ||
# Removing the warning would require passing a fully-fledged linker script to bypass gcc's default. | ||
gcc -g $^ -Wl,--emit-relocs -o $@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
__attribute__((section(".coffee_section"))) | ||
int coffee(void) { | ||
return 0; | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
SECTIONS | ||
{ | ||
. = 0xC0FFEE; | ||
.coffee_section : {} | ||
} |