]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: allow duplicated weak symbols on Mach-O
authorCherry Zhang <cherryyz@google.com>
Sat, 30 Mar 2019 14:49:09 +0000 (10:49 -0400)
committerCherry Zhang <cherryyz@google.com>
Sat, 30 Mar 2019 17:33:18 +0000 (17:33 +0000)
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 <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/cmd/link/internal/loadmacho/ldmacho.go

index 85aa606ff51efaf40ebb48ec5feb0fb8117d165d..e2b0d63aa3686ce5cc4267febb7d144574294111 100644 (file)
@@ -43,11 +43,6 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE.
 */
-const (
-       N_EXT  = 0x01
-       N_TYPE = 0x1e
-       N_STAB = 0xe0
-)
 
 // TODO(crawshaw): de-duplicate these symbols with cmd/internal/ld
 const (
@@ -161,6 +156,19 @@ type ldMachoDysymtab struct {
        indir          []uint32
 }
 
+// ldMachoSym.type_
+const (
+       N_EXT  = 0x01
+       N_TYPE = 0x1e
+       N_STAB = 0xe0
+)
+
+// ldMachoSym.desc
+const (
+       N_WEAK_REF = 0x40
+       N_WEAK_DEF = 0x80
+)
+
 const (
        LdMachoCpuVax         = 1
        LdMachoCpu68000       = 6
@@ -616,6 +624,9 @@ func Load(arch *sys.Arch, syms *sym.Symbols, f *bio.Reader, pkg string, length i
                if machsym.type_&N_EXT == 0 {
                        s.Attr |= sym.AttrDuplicateOK
                }
+               if machsym.desc&(N_WEAK_REF|N_WEAK_DEF) != 0 {
+                       s.Attr |= sym.AttrDuplicateOK
+               }
                machsym.sym = s
                if machsym.sectnum == 0 { // undefined
                        continue