Commit 45f75950 authored by Ian Lance Taylor's avatar Ian Lance Taylor

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 <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 610d5221
...@@ -137,6 +137,8 @@ const ( ...@@ -137,6 +137,8 @@ const (
ElfSymTypeFunc = 2 ElfSymTypeFunc = 2
ElfSymTypeSection = 3 ElfSymTypeSection = 3
ElfSymTypeFile = 4 ElfSymTypeFile = 4
ElfSymTypeCommon = 5
ElfSymTypeTLS = 6
) )
const ( const (
...@@ -751,10 +753,10 @@ func ldelf(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) { ...@@ -751,10 +753,10 @@ func ldelf(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
goto bad goto bad
} }
symbols[i] = sym.sym symbols[i] = sym.sym
if sym.type_ != ElfSymTypeFunc && sym.type_ != ElfSymTypeObject && sym.type_ != ElfSymTypeNone { if sym.type_ != ElfSymTypeFunc && sym.type_ != ElfSymTypeObject && sym.type_ != ElfSymTypeNone && sym.type_ != ElfSymTypeCommon {
continue continue
} }
if sym.shndx == ElfSymShnCommon { if sym.shndx == ElfSymShnCommon || sym.type_ == ElfSymTypeCommon {
s = sym.sym s = sym.sym
if uint64(s.Size) < sym.size { if uint64(s.Size) < sym.size {
s.Size = int64(sym.size) s.Size = int64(sym.size)
...@@ -1035,7 +1037,7 @@ func readelfsym(ctxt *Link, elfobj *ElfObj, i int, sym *ElfSym, needSym int, loc ...@@ -1035,7 +1037,7 @@ func readelfsym(ctxt *Link, elfobj *ElfObj, i int, sym *ElfSym, needSym int, loc
case ElfSymTypeSection: case ElfSymTypeSection:
s = elfobj.sect[sym.shndx].sym s = elfobj.sect[sym.shndx].sym
case ElfSymTypeObject, ElfSymTypeFunc, ElfSymTypeNone: case ElfSymTypeObject, ElfSymTypeFunc, ElfSymTypeNone, ElfSymTypeCommon:
switch sym.bind { switch sym.bind {
case ElfSymBindGlobal: case ElfSymBindGlobal:
if needSym != 0 { if needSym != 0 {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment