diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2020-10-26 08:28:39 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2020-10-26 15:44:28 +0100 |
| commit | 8062b02d8f2d7cfd74ee564821cb0932eab87762 (patch) | |
| tree | bba214a0836b04509228b03edd9624a67d37f7e1 /pkg | |
| parent | e6e35dba937599d098fc034eff2686e5ddc409e9 (diff) | |
pkg/report: add test for CONFIG_RANDOMIZE_BASE
Diffstat (limited to 'pkg')
| -rw-r--r-- | pkg/cover/report.go | 4 | ||||
| -rw-r--r-- | pkg/cover/report_test.go | 29 |
2 files changed, 29 insertions, 4 deletions
diff --git a/pkg/cover/report.go b/pkg/cover/report.go index 4e6b7cd0d..5cf753738 100644 --- a/pkg/cover/report.go +++ b/pkg/cover/report.go @@ -627,10 +627,6 @@ func readTextRanges(file *elf.File) ([]pcRange, []*compileUnit, error) { // It's unclear if we also need some offset on top of text.Addr, // it gives approximately correct addresses, but not necessary precisely // correct addresses. - // It would be good to add a test for this, but it's unclear what flag - // combination will give a similar binary. The following still gives - // matching .text/symbols/PC ranges: - // gcc test.c -g -fpie -pie -Wl,--section-start=.text=0x33300000 r[0] += text.Addr r[1] += text.Addr if r[0] >= r[1] || r[0] < text.Addr || r[1] > text.Addr+text.Size { diff --git a/pkg/cover/report_test.go b/pkg/cover/report_test.go index b48ea2370..af6315ed4 100644 --- a/pkg/cover/report_test.go +++ b/pkg/cover/report_test.go @@ -33,6 +33,7 @@ type Test struct { Progs []Prog AddCover bool Result string + Supports func(target *targets.Target) bool } func TestReportGenerator(t *testing.T) { @@ -65,6 +66,31 @@ func TestReportGenerator(t *testing.T) { AddCover: true, CFlags: []string{"-fsanitize-coverage=trace-pc", "-g"}, }, + { + Name: "good-pie", + AddCover: true, + CFlags: []string{"-fsanitize-coverage=trace-pc", "-g", "-fpie", "-pie", + "-Wl,--section-start=.text=0x33300000"}, + Supports: func(target *targets.Target) bool { + return target.OS == targets.Fuchsia || + // Fails with "relocation truncated to fit: R_AARCH64_CALL26 against symbol `memcpy'". + target.OS == targets.Linux && target.Arch != targets.ARM64 + }, + }, + { + Name: "good-pie-relocs", + AddCover: true, + // This produces a binary that resembles CONFIG_RANDOMIZE_BASE=y. + // Symbols and .text section has addresses around 0x33300000, + // but debug info has all PC ranges around 0 address. + CFlags: []string{"-fsanitize-coverage=trace-pc", "-g", "-fpie", "-pie", + "-Wl,--section-start=.text=0x33300000,--emit-relocs"}, + Supports: func(target *targets.Target) bool { + return target.OS == targets.Fuchsia || + target.OS == targets.Linux && target.Arch != targets.ARM64 && + target.Arch != targets.ARM && target.Arch != targets.I386 + }, + }, } t.Parallel() for os, arches := range targets.List { @@ -84,6 +110,9 @@ func TestReportGenerator(t *testing.T) { for _, test := range tests { test := test t.Run(test.Name, func(t *testing.T) { + if test.Supports != nil && !test.Supports(target) { + t.Skip("unsupported target") + } t.Parallel() testReportGenerator(t, target, test) }) |
