45f759500ec80a1362deecd3693cbe44a354bf98.patch 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. Upstream: yes
  2. From 45f759500ec80a1362deecd3693cbe44a354bf98 Mon Sep 17 00:00:00 2001
  3. From: Ian Lance Taylor <iant@golang.org>
  4. Date: Mon, 28 Nov 2016 16:19:03 -0800
  5. Subject: [PATCH] cmd/link: handle STT_COMMON symbols
  6. Tested by running
  7. GOTRACEBACK=2 CGO_CFLAGS="-Wa,--elf-stt-common=yes" go test -ldflags=-linkmode=internal
  8. in misc/cgo/test. That failed before this CL, succeeded after.
  9. I don't think it's worth doing that as a regular test, though,
  10. especially since only recent versions of the GNU binutils support the
  11. --elf-stt-common option.
  12. Fixes #18088.
  13. Change-Id: I893d86181faee217b1504c054b0ed3f7c8d977d3
  14. Reviewed-on: https://go-review.googlesource.com/33653
  15. Run-TryBot: Ian Lance Taylor <iant@golang.org>
  16. TryBot-Result: Gobot Gobot <gobot@golang.org>
  17. Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
  18. ---
  19. src/cmd/link/internal/ld/ldelf.go | 8 +++++---
  20. 1 file changed, 5 insertions(+), 3 deletions(-)
  21. diff --git a/src/cmd/link/internal/ld/ldelf.go b/src/cmd/link/internal/ld/ldelf.go
  22. index d700aa6..00e8f37 100644
  23. --- a/src/cmd/link/internal/ld/ldelf.go
  24. +++ b/src/cmd/link/internal/ld/ldelf.go
  25. @@ -137,6 +137,8 @@ const (
  26. ElfSymTypeFunc = 2
  27. ElfSymTypeSection = 3
  28. ElfSymTypeFile = 4
  29. + ElfSymTypeCommon = 5
  30. + ElfSymTypeTLS = 6
  31. )
  32. const (
  33. @@ -751,10 +753,10 @@ func ldelf(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
  34. goto bad
  35. }
  36. symbols[i] = sym.sym
  37. - if sym.type_ != ElfSymTypeFunc && sym.type_ != ElfSymTypeObject && sym.type_ != ElfSymTypeNone {
  38. + if sym.type_ != ElfSymTypeFunc && sym.type_ != ElfSymTypeObject && sym.type_ != ElfSymTypeNone && sym.type_ != ElfSymTypeCommon {
  39. continue
  40. }
  41. - if sym.shndx == ElfSymShnCommon {
  42. + if sym.shndx == ElfSymShnCommon || sym.type_ == ElfSymTypeCommon {
  43. s = sym.sym
  44. if uint64(s.Size) < sym.size {
  45. s.Size = int64(sym.size)
  46. @@ -1035,7 +1037,7 @@ func readelfsym(ctxt *Link, elfobj *ElfObj, i int, sym *ElfSym, needSym int, loc
  47. case ElfSymTypeSection:
  48. s = elfobj.sect[sym.shndx].sym
  49. - case ElfSymTypeObject, ElfSymTypeFunc, ElfSymTypeNone:
  50. + case ElfSymTypeObject, ElfSymTypeFunc, ElfSymTypeNone, ElfSymTypeCommon:
  51. switch sym.bind {
  52. case ElfSymBindGlobal:
  53. if needSym != 0 {