Skip to content

Commit 637f34f

Browse files
committed
cmd/link: allow duplicated weak symbols on Mach-O
This fixes cgo test issue29563 on Darwin. Updates #29563. Change-Id: If480078461247cd7c95931ae3ad4ca89736dd550 Reviewed-on: https://go-review.googlesource.com/c/go/+/170015 Run-TryBot: Cherry Zhang <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 6e37e3a commit 637f34f

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/cmd/link/internal/loadmacho/ldmacho.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
4343
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
4444
THE SOFTWARE.
4545
*/
46-
const (
47-
N_EXT = 0x01
48-
N_TYPE = 0x1e
49-
N_STAB = 0xe0
50-
)
5146

5247
// TODO(crawshaw): de-duplicate these symbols with cmd/internal/ld
5348
const (
@@ -161,6 +156,19 @@ type ldMachoDysymtab struct {
161156
indir []uint32
162157
}
163158

159+
// ldMachoSym.type_
160+
const (
161+
N_EXT = 0x01
162+
N_TYPE = 0x1e
163+
N_STAB = 0xe0
164+
)
165+
166+
// ldMachoSym.desc
167+
const (
168+
N_WEAK_REF = 0x40
169+
N_WEAK_DEF = 0x80
170+
)
171+
164172
const (
165173
LdMachoCpuVax = 1
166174
LdMachoCpu68000 = 6
@@ -616,6 +624,9 @@ func Load(arch *sys.Arch, syms *sym.Symbols, f *bio.Reader, pkg string, length i
616624
if machsym.type_&N_EXT == 0 {
617625
s.Attr |= sym.AttrDuplicateOK
618626
}
627+
if machsym.desc&(N_WEAK_REF|N_WEAK_DEF) != 0 {
628+
s.Attr |= sym.AttrDuplicateOK
629+
}
619630
machsym.sym = s
620631
if machsym.sectnum == 0 { // undefined
621632
continue

0 commit comments

Comments
 (0)