xref: /llvm-project/llvm/test/tools/llvm-objcopy/MachO/weaken.s (revision 0807846a9ee6e2c24cc84feeb6a80ee22015a4a0)
1# REQUIRES: x86-registered-target
2
3# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos %s -o %t
4
5# RUN: llvm-objcopy -W _func %t %t2
6# RUN: llvm-readobj --symbols %t2 | FileCheck %s -check-prefix=CHECK-1
7
8# CHECK-1:      Symbol {
9# CHECK-1-NEXT:   Name: _foo (1)
10# CHECK-1-NEXT:   Extern
11# CHECK-1-NEXT:   Type: Section (0xE)
12# CHECK-1-NEXT:   Section: __const (0x2)
13# CHECK-1-NEXT:   RefType: UndefinedNonLazy (0x0)
14# CHECK-1-NEXT:   Flags [ (0x0)
15# CHECK-1-NEXT:   ]
16# CHECK-1-NEXT:   Value: 0x0
17# CHECK-1-NEXT: }
18# CHECK-1-NEXT: Symbol {
19# CHECK-1-NEXT:   Name: _func (6)
20# CHECK-1-NEXT:   Extern
21# CHECK-1-NEXT:   Type: Section (0xE)
22# CHECK-1-NEXT:   Section: __text (0x1)
23# CHECK-1-NEXT:   RefType: UndefinedNonLazy (0x0)
24# CHECK-1-NEXT:   Flags [ (0x80)
25# CHECK-1-NEXT:     WeakDef (0x80)
26# CHECK-1-NEXT:   ]
27# CHECK-1-NEXT:   Value: 0x0
28# CHECK-1-NEXT: }
29
30# RUN: echo _foo > %t.weaken.txt
31# RUN: echo _func >> %t.weaken.txt
32# RUN: llvm-objcopy --weaken-symbols %t.weaken.txt %t %t3
33# RUN: llvm-readobj --symbols %t3 | FileCheck %s -check-prefix=CHECK-2
34
35# CHECK-2:      Symbol {
36# CHECK-2-NEXT:   Name: _foo (1)
37# CHECK-2-NEXT:   Extern
38# CHECK-2-NEXT:   Type: Section (0xE)
39# CHECK-2-NEXT:   Section: __const (0x2)
40# CHECK-2-NEXT:   RefType: UndefinedNonLazy (0x0)
41# CHECK-2-NEXT:   Flags [ (0x80)
42# CHECK-2-NEXT:     WeakDef (0x80)
43# CHECK-2-NEXT:   ]
44# CHECK-2-NEXT:   Value: 0x0
45# CHECK-2-NEXT: }
46# CHECK-2-NEXT: Symbol {
47# CHECK-2-NEXT:   Name: _func (6)
48# CHECK-2-NEXT:   Extern
49# CHECK-2-NEXT:   Type: Section (0xE)
50# CHECK-2-NEXT:   Section: __text (0x1)
51# CHECK-2-NEXT:   RefType: UndefinedNonLazy (0x0)
52# CHECK-2-NEXT:   Flags [ (0x80)
53# CHECK-2-NEXT:     WeakDef (0x80)
54# CHECK-2-NEXT:   ]
55# CHECK-2-NEXT:   Value: 0x0
56# CHECK-2-NEXT: }
57
58## Verify --weaken-symbol plays nice with --redefine-sym.
59# RUN: llvm-objcopy -W _foo --redefine-sym _foo=_bar %t %t4
60# RUN: llvm-readobj --symbols %t4 | FileCheck %s -check-prefix=CHECK-3
61
62# CHECK-3:      Symbol {
63# CHECK-3-NEXT:   Name: _bar (1)
64# CHECK-3-NEXT:   Extern
65# CHECK-3-NEXT:   Type: Section (0xE)
66# CHECK-3-NEXT:   Section: __const (0x2)
67# CHECK-3-NEXT:   RefType: UndefinedNonLazy (0x0)
68# CHECK-3-NEXT:   Flags [ (0x80)
69# CHECK-3-NEXT:     WeakDef (0x80)
70# CHECK-3-NEXT:   ]
71# CHECK-3-NEXT:   Value: 0x0
72# CHECK-3-NEXT: }
73# CHECK-3-NEXT: Symbol {
74# CHECK-3-NEXT:   Name: _func (6)
75# CHECK-3-NEXT:   Extern
76# CHECK-3-NEXT:   Type: Section (0xE)
77# CHECK-3-NEXT:   Section: __text (0x1)
78# CHECK-3-NEXT:   RefType: UndefinedNonLazy (0x0)
79# CHECK-3-NEXT:   Flags [ (0x0)
80# CHECK-3-NEXT:   ]
81# CHECK-3-NEXT:   Value: 0x0
82# CHECK-3-NEXT: }
83
84.globl _func
85_func:
86
87.section __TEXT,__const
88.globl _foo
89_foo:
90