Skip to content

Commit b5b7e9d

Browse files
committed
Add good / bad binaries
1 parent a9503c5 commit b5b7e9d

File tree

5 files changed

+26
-11
lines changed

5 files changed

+26
-11
lines changed

Makefile

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
.PHONY: all test
1+
.PHONY: all test testbinaries
22

33
all: test
44

5-
testdata/repro:
5+
testbinaries:
66
cd testdata && make
77

88
dwarf-relocation-golang-bug: main.go
99
go build
1010

11-
test: testdata/repro dwarf-relocation-golang-bug
11+
test: testbinaries dwarf-relocation-golang-bug
12+
@echo "-------------------------"
13+
@./test.sh testdata/good
1214
@echo
13-
@echo "Running test"
14-
@./test.sh
15+
@echo "-------------------------"
16+
@./test.sh testdata/bad
17+
@echo "-------------------------"

main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import (
44
"debug/elf"
55
"fmt"
66
"log"
7+
"os"
78
)
89

910
func main() {
10-
file, err := elf.Open("testdata/repro")
11+
file, err := elf.Open(os.Args[1])
1112
if err != nil {
1213
log.Fatal(err)
1314
}

test.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
#!/bin/bash -eu
2+
set -o pipefail
23

4+
file="$1"
5+
6+
echo "Testing ${file}..."
37
echo "Actual ranges:"
4-
llvm-dwarfdump testdata/repro --name=repro.c | grep -A2 DW_AT_ranges | tail -2 | sed 's/))/)/' | tr -d ' '
8+
llvm-dwarfdump ${file} --name=repro.c | grep -A2 DW_AT_ranges | tail -2 | sed -e 's/0x0*/0x/g' -e 's/))/)/' | tr -d ' '
59

610
echo
711
echo "Ranges derived from Golang's debug/elf + debug/dwarf"
8-
./dwarf-relocation-golang-bug
12+
./dwarf-relocation-golang-bug ${file}
913

testdata/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
repro
1+
good
2+
bad

testdata/Makefile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
.PHONY: all
22

3-
repro: repro.c repro.ld
3+
all: bad good
4+
5+
bad: repro.c repro.ld
46
# The following command will likely print a warning (about a missing -T option), which should be ignored.
57
# Removing the warning would require passing a fully-fledged linker script to bypass gcc's default.
6-
gcc -g $^ -Wl,--emit-relocs -o $@
8+
gcc -g $^ -Wl,--emit-relocs -Wl,--discard-none -o $@
9+
10+
good: repro.c repro.ld
11+
# Same, but without --emit-relocs
12+
gcc -g $^ -o $@
713

0 commit comments

Comments
 (0)