[llvm] [objcopy] Implement --weaken, --weaken-symbol(s) flags for MachO Object Files (PR #70560)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 31 22:22:38 PDT 2023


================
@@ -0,0 +1,36 @@
+# REQUIRES: x86-registered-target
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos %s -o %t
+
+# RUN: llvm-objcopy --weaken %t %t2
+# RUN: llvm-readobj --symbols %t2 | FileCheck %s
+
+# CHECK:      Symbol {
+# CHECK-NEXT:   Name: _foo (1)
+# CHECK-NEXT:   Extern
+# CHECK-NEXT:   Type: Section (0xE)
+# CHECK-NEXT:   Section: __const (0x2)
+# CHECK-NEXT:   RefType: UndefinedNonLazy (0x0)
+# CHECK-NEXT:   Flags [ (0x80)
+# CHECK-NEXT:     WeakDef (0x80)
+# CHECK-NEXT:   ]
+# CHECK-NEXT:   Value: 0x0
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT:   Name: _func (6)
+# CHECK-NEXT:   Extern
+# CHECK-NEXT:   Type: Section (0xE)
+# CHECK-NEXT:   Section: __text (0x1)
+# CHECK-NEXT:   RefType: UndefinedNonLazy (0x0)
+# CHECK-NEXT:   Flags [ (0x80)
+# CHECK-NEXT:     WeakDef (0x80)
+# CHECK-NEXT:   ]
+# CHECK-NEXT:   Value: 0x0
+# CHECK-NEXT: }
+
+.globl _func
+_func:
+
+.section __TEXT,__const
+.globl _foo
+_foo:
----------------
MaskRay wrote:

This should test other types of symbols, e.g. weak symbol, local symbol.

https://github.com/llvm/llvm-project/pull/70560


More information about the llvm-commits mailing list