|
31 | 31 | package ld |
32 | 32 |
|
33 | 33 | import ( |
| 34 | + "cmd/internal/obj" |
34 | 35 | "cmd/internal/objabi" |
35 | 36 | "cmd/link/internal/loader" |
36 | 37 | "cmd/link/internal/sym" |
@@ -102,10 +103,14 @@ func putelfsym(ctxt *Link, x loader.Sym, typ elf.SymType, curbind elf.SymBind) { |
102 | 103 | elfshnum = xosect.Elfsect.(*ElfShdr).shnum |
103 | 104 | } |
104 | 105 |
|
| 106 | + sname := ldr.SymExtname(x) |
| 107 | + |
105 | 108 | // One pass for each binding: elf.STB_LOCAL, elf.STB_GLOBAL, |
106 | 109 | // maybe one day elf.STB_WEAK. |
107 | 110 | bind := elf.STB_GLOBAL |
108 | | - if ldr.IsFileLocal(x) || ldr.AttrVisibilityHidden(x) || ldr.AttrLocal(x) { |
| 111 | + if ldr.IsFileLocal(x) && !isStaticTmp(sname) || ldr.AttrVisibilityHidden(x) || ldr.AttrLocal(x) { |
| 112 | + // Static tmp is package local, but a package can be shared among multiple DSOs. |
| 113 | + // They need to have a single view of the static tmp that are writable. |
109 | 114 | bind = elf.STB_LOCAL |
110 | 115 | } |
111 | 116 |
|
@@ -140,8 +145,6 @@ func putelfsym(ctxt *Link, x loader.Sym, typ elf.SymType, curbind elf.SymBind) { |
140 | 145 | other |= 3 << 5 |
141 | 146 | } |
142 | 147 |
|
143 | | - sname := ldr.SymExtname(x) |
144 | | - |
145 | 148 | // When dynamically linking, we create Symbols by reading the names from |
146 | 149 | // the symbol tables of the shared libraries and so the names need to |
147 | 150 | // match exactly. Tools like DTrace will have to wait for now. |
@@ -823,3 +826,7 @@ func setCarrierSize(typ sym.SymKind, sz int64) { |
823 | 826 | } |
824 | 827 | CarrierSymByType[typ].Size = sz |
825 | 828 | } |
| 829 | + |
| 830 | +func isStaticTmp(name string) bool { |
| 831 | + return strings.Contains(name, "."+obj.StaticNamePref) |
| 832 | +} |
0 commit comments