Skip to content

Commit 45f7595

Browse files
cmd/link: handle STT_COMMON symbols
Tested by running GOTRACEBACK=2 CGO_CFLAGS="-Wa,--elf-stt-common=yes" go test -ldflags=-linkmode=internal in misc/cgo/test. That failed before this CL, succeeded after. I don't think it's worth doing that as a regular test, though, especially since only recent versions of the GNU binutils support the --elf-stt-common option. Fixes #18088. Change-Id: I893d86181faee217b1504c054b0ed3f7c8d977d3 Reviewed-on: https://go-review.googlesource.com/33653 Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 610d522 commit 45f7595

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/cmd/link/internal/ld/ldelf.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ const (
137137
ElfSymTypeFunc = 2
138138
ElfSymTypeSection = 3
139139
ElfSymTypeFile = 4
140+
ElfSymTypeCommon = 5
141+
ElfSymTypeTLS = 6
140142
)
141143

142144
const (
@@ -751,10 +753,10 @@ func ldelf(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
751753
goto bad
752754
}
753755
symbols[i] = sym.sym
754-
if sym.type_ != ElfSymTypeFunc && sym.type_ != ElfSymTypeObject && sym.type_ != ElfSymTypeNone {
756+
if sym.type_ != ElfSymTypeFunc && sym.type_ != ElfSymTypeObject && sym.type_ != ElfSymTypeNone && sym.type_ != ElfSymTypeCommon {
755757
continue
756758
}
757-
if sym.shndx == ElfSymShnCommon {
759+
if sym.shndx == ElfSymShnCommon || sym.type_ == ElfSymTypeCommon {
758760
s = sym.sym
759761
if uint64(s.Size) < sym.size {
760762
s.Size = int64(sym.size)
@@ -1035,7 +1037,7 @@ func readelfsym(ctxt *Link, elfobj *ElfObj, i int, sym *ElfSym, needSym int, loc
10351037
case ElfSymTypeSection:
10361038
s = elfobj.sect[sym.shndx].sym
10371039

1038-
case ElfSymTypeObject, ElfSymTypeFunc, ElfSymTypeNone:
1040+
case ElfSymTypeObject, ElfSymTypeFunc, ElfSymTypeNone, ElfSymTypeCommon:
10391041
switch sym.bind {
10401042
case ElfSymBindGlobal:
10411043
if needSym != 0 {

0 commit comments

Comments
 (0)