]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/ld: don't include padding length in size of the note section
authorShenghou Ma <minux.ma@gmail.com>
Wed, 5 Mar 2014 19:40:55 +0000 (14:40 -0500)
committerRuss Cox <rsc@golang.org>
Wed, 5 Mar 2014 19:40:55 +0000 (14:40 -0500)
Recently NetBSD starts to enforce this, and refuses to execute
the program if n is larger than the sum of entry sizes.

Before:
$ readelf -n ../bin/go.old
Notes at offset 0x00000bd0 with length 0x00000019:
  Owner         Data size       Description
  NetBSD                0x00000004      NT_VERSION (version)
readelf: Warning: corrupt note found at offset 18 into core notes
readelf: Warning:  type: 0, namesize: 00000000, descsize: 00000000
$ readelf -n ../bin/go
Notes at offset 0x00000bd0 with length 0x00000018:
Owner         Data size       Description
NetBSD                0x00000004      NT_VERSION (version)

LGTM=iant
R=iant
CC=golang-codereviews
https://golang.org/cl/70710043

src/cmd/ld/elf.c

index 4c0d07173319410846fad19058bb13ba3589bb53..3b0f578814fb6df2ec29845b0c2f9739edee3e72 100644 (file)
@@ -355,7 +355,7 @@ elfnote(ElfShdr *sh, uint64 startva, uint64 resoff, int sz)
        sh->addralign = 4;
        sh->addr = startva + resoff - n;
        sh->off = resoff - n;
-       sh->size = n;
+       sh->size = n - resoff % 4;
 
        return n;
 }