mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/link: handle grouped resource sections
The Go PE linker does not support enough generalized PE logic to properly handle .rsrc sections gracefully. Instead a few things are special cased for these. The linker also does not support PE's "grouped sections" features, in which input objects have several named sections that are sorted, merged, and renamed in the output file. In the past, more sophisticated support for resources or for PE features like grouped sections have not been necessary, as Go's own object formats are pretty vanilla, and GNU binutils also produces pretty vanilla objects where all sections are already merged. However, GNU binutils is lagging with arm support, and here LLVM has picked up the slack. In particular, LLVM has its own rc/cvtres combo, which are glued together in mingw LLVM distributions as windres, a command line compatible tool with binutils' windres, which supports arm and arm64. But there's a key difference between binutils' windres and LLVM's windres: the LLVM one uses proper grouped sections. So, this commit adds grouped sections support for resource sections to the linker. We don't attempt to plumb generic support for grouped sections, just as there isn't generic support already for what resources require. Instead we augment the resource handling logic to deal with standard two-section resource objects. We also add a test for this, akin to the current test for more vanilla binutils resource objects, and make sure that the rsrc tests are always performed. Fixes #42866. Fixes #43182. Change-Id: I059450021405cdf2ef1c195ddbab3960764ad711 Reviewed-on: https://go-review.googlesource.com/c/go/+/268337 Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com> Trust: Alex Brainman <alex.brainman@gmail.com> Trust: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
c06a354bcc
commit
c9fb4eb0a2
6 changed files with 124 additions and 49 deletions
|
|
@ -786,6 +786,25 @@ func TestPErsrc(t *testing.T) {
|
|||
if !bytes.Contains(b, []byte("Hello Gophers!")) {
|
||||
t.Fatalf("binary does not contain expected content")
|
||||
}
|
||||
|
||||
pkgdir = filepath.Join("testdata", "testPErsrc-complex")
|
||||
exe = filepath.Join(tmpdir, "a.exe")
|
||||
cmd = exec.Command(testenv.GoToolPath(t), "build", "-o", exe)
|
||||
cmd.Dir = pkgdir
|
||||
// cmd.Env = append(os.Environ(), "GOOS=windows", "GOARCH=amd64") // uncomment if debugging in a cross-compiling environment
|
||||
out, err = cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
t.Fatalf("building failed: %v, output:\n%s", err, out)
|
||||
}
|
||||
|
||||
// Check that the binary contains the rsrc data
|
||||
b, err = ioutil.ReadFile(exe)
|
||||
if err != nil {
|
||||
t.Fatalf("reading output failed: %v", err)
|
||||
}
|
||||
if !bytes.Contains(b, []byte("resname RCDATA a.rc")) {
|
||||
t.Fatalf("binary does not contain expected content")
|
||||
}
|
||||
}
|
||||
|
||||
func TestContentAddressableSymbols(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue