| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| # REQUIRES: x86 | ||
| # RUN: split-file %s %t | ||
|
|
||
| # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/test.s -o %t/test.o | ||
| # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/same-size.s -o %t/same-size.o | ||
| # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/smaller-size.s -o %t/smaller-size.o | ||
| # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/zero-align.s -o %t/zero-align.o | ||
| # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/zero-align-round-up.s -o %t/zero-align-round-up.o | ||
|
|
||
| ## Check that we pick the definition with the larger size, regardless of | ||
| ## its alignment. | ||
| # RUN: lld -flavor darwinnew %t/test.o %t/smaller-size.o -order_file %t/order -o %t/test | ||
| # RUN: llvm-objdump --section-headers --syms %t/test | FileCheck %s --check-prefix=SMALLER-ALIGNMENT | ||
| # RUN: lld -flavor darwinnew %t/smaller-size.o %t/test.o -order_file %t/order -o %t/test | ||
| # RUN: llvm-objdump --section-headers --syms %t/test | FileCheck %s --check-prefix=SMALLER-ALIGNMENT | ||
|
|
||
| ## When the sizes are equal, we pick the symbol whose file occurs later in the | ||
| ## command-line argument list. | ||
| # RUN: lld -flavor darwinnew %t/test.o %t/same-size.o -order_file %t/order -o %t/test | ||
| # RUN: llvm-objdump --section-headers --syms %t/test | FileCheck %s --check-prefix=LARGER-ALIGNMENT | ||
| # RUN: lld -flavor darwinnew %t/same-size.o %t/test.o -order_file %t/order -o %t/test | ||
| # RUN: llvm-objdump --section-headers --syms %t/test | FileCheck %s --check-prefix=SMALLER-ALIGNMENT | ||
|
|
||
| # RUN: lld -flavor darwinnew %t/test.o %t/zero-align.o -order_file %t/order -o %t/test | ||
| # RUN: llvm-objdump --section-headers --syms %t/test | FileCheck %s --check-prefix=LARGER-ALIGNMENT | ||
| # RUN: lld -flavor darwinnew %t/zero-align.o %t/test.o -order_file %t/order -o %t/test | ||
| # RUN: llvm-objdump --section-headers --syms %t/test | FileCheck %s --check-prefix=LARGER-ALIGNMENT | ||
|
|
||
| # RUN: lld -flavor darwinnew %t/test.o %t/zero-align-round-up.o -order_file %t/order -o %t/test | ||
| # RUN: llvm-objdump --section-headers --syms %t/test | FileCheck %s --check-prefix=LARGER-ALIGNMENT | ||
| # RUN: lld -flavor darwinnew %t/zero-align-round-up.o %t/test.o -order_file %t/order -o %t/test | ||
| # RUN: llvm-objdump --section-headers --syms %t/test | FileCheck %s --check-prefix=LARGER-ALIGNMENT | ||
|
|
||
| # SMALLER-ALIGNMENT-LABEL: Sections: | ||
| # SMALLER-ALIGNMENT: __common {{[0-9a-f]+}} [[#%x, COMMON_START:]] BSS | ||
|
|
||
| # SMALLER-ALIGNMENT-LABEL: SYMBOL TABLE: | ||
| # SMALLER-ALIGNMENT-DAG: [[#COMMON_START]] g O __DATA,__common _check_size | ||
| # SMALLER-ALIGNMENT-DAG: [[#COMMON_START + 2]] g O __DATA,__common _end_marker | ||
| # SMALLER-ALIGNMENT-DAG: [[#COMMON_START + 8]] g O __DATA,__common _check_alignment | ||
|
|
||
| # LARGER-ALIGNMENT-LABEL: Sections: | ||
| # LARGER-ALIGNMENT: __common {{[0-9a-f]+}} [[#%x, COMMON_START:]] BSS | ||
|
|
||
| # LARGER-ALIGNMENT-LABEL: SYMBOL TABLE: | ||
| # LARGER-ALIGNMENT-DAG: [[#COMMON_START]] g O __DATA,__common _check_size | ||
| # LARGER-ALIGNMENT-DAG: [[#COMMON_START + 2]] g O __DATA,__common _end_marker | ||
| # LARGER-ALIGNMENT-DAG: [[#COMMON_START + 16]] g O __DATA,__common _check_alignment | ||
|
|
||
| #--- order | ||
| ## Order is important as we determine the size of a given symbol via the | ||
| ## address of the next symbol. | ||
| _check_size | ||
| _end_marker | ||
| _check_alignment | ||
|
|
||
| #--- smaller-size.s | ||
| .comm _check_size, 1, 1 | ||
| .comm _check_alignment, 1, 4 | ||
|
|
||
| #--- same-size.s | ||
| .comm _check_size, 2, 1 | ||
| .comm _check_alignment, 2, 4 | ||
|
|
||
| #--- zero-align.s | ||
| .comm _check_size, 2, 1 | ||
| ## If alignment is set to zero, use the size to determine the alignment. | ||
| .comm _check_alignment, 16, 0 | ||
|
|
||
| #--- zero-align-round-up.s | ||
| .comm _check_size, 2, 1 | ||
| ## If alignment is set to zero, use the size to determine the alignment. If the | ||
| ## size is not a power of two, round it up. (In this case, 14 rounds to 16.) | ||
| .comm _check_alignment, 14, 0 | ||
|
|
||
| #--- test.s | ||
| .comm _check_size, 2, 1 | ||
| .comm _end_marker, 1 | ||
| .comm _check_alignment, 2, 3 | ||
|
|
||
| .globl _main | ||
| _main: | ||
| ret |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| # REQUIRES: x86 | ||
| # RUN: split-file %s %t | ||
|
|
||
| # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/common.s -o %t/common.o | ||
| # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/weak-common.s -o %t/weak-common.o | ||
| # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/defined.s -o %t/defined.o | ||
| # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/weak-defined.s -o %t/weak-defined.o | ||
| # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/libfoo.s -o %t/libfoo.o | ||
| # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/test.s -o %t/test.o | ||
| # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/calls-foo.s -o %t/calls-foo.o | ||
|
|
||
| # RUN: lld -flavor darwinnew -syslibroot %S/Inputs/MacOSX.sdk -lSystem -order_file %t/order -dylib %t/libfoo.o -o %t/libfoo.dylib | ||
|
|
||
| # RUN: rm -f %t/defined.a %t/weak-defined-and-common.a | ||
| # RUN: llvm-ar rcs %t/defined.a %t/defined.o | ||
| # RUN: llvm-ar rcs %t/weak-defined-and-common.a %t/weak-defined.o %t/common.o | ||
|
|
||
| ## The weak attribute appears to have no effect on common symbols. Given two | ||
| ## common symbols of the same name, we always pick the one with the larger size, | ||
| ## regardless of whether it is weak. Moreover, the resolved symbol in the output | ||
| ## file will always be non-weak, even if the winning input symbol definition was | ||
| ## weak. | ||
| # RUN: lld -flavor darwinnew -syslibroot %S/Inputs/MacOSX.sdk -lSystem -order_file %t/order %t/common.o %t/weak-common.o %t/test.o -o %t/test | ||
| # RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=LARGER-COMMON | ||
| # RUN: lld -flavor darwinnew -syslibroot %S/Inputs/MacOSX.sdk -lSystem -order_file %t/order %t/weak-common.o %t/common.o %t/test.o -o %t/test | ||
| # RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=LARGER-COMMON | ||
|
|
||
| ## Defined symbols are the only ones that take precedence over common symbols. | ||
| # RUN: lld -flavor darwinnew -syslibroot %S/Inputs/MacOSX.sdk -lSystem -order_file %t/order %t/defined.o %t/common.o %t/test.o -o %t/test | ||
| # RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=DEFINED | ||
| # RUN: lld -flavor darwinnew -syslibroot %S/Inputs/MacOSX.sdk -lSystem -order_file %t/order %t/common.o %t/defined.o %t/test.o -o %t/test | ||
| # RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=DEFINED | ||
|
|
||
| # RUN: lld -flavor darwinnew -syslibroot %S/Inputs/MacOSX.sdk -lSystem -order_file %t/order %t/weak-defined.o %t/common.o %t/test.o -o %t/test | ||
| # RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=WEAK-DEFINED | ||
| # RUN: lld -flavor darwinnew -syslibroot %S/Inputs/MacOSX.sdk -lSystem -order_file %t/order %t/common.o %t/weak-defined.o %t/test.o -o %t/test | ||
| # RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=WEAK-DEFINED | ||
|
|
||
| ## Common symbols take precedence over archive symbols. | ||
| # RUN: lld -flavor darwinnew -syslibroot %S/Inputs/MacOSX.sdk -lSystem -order_file %t/order %t/defined.a %t/weak-common.o %t/test.o -o %t/test | ||
| # RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=LARGER-COMMON | ||
| # RUN: lld -flavor darwinnew -syslibroot %S/Inputs/MacOSX.sdk -lSystem -order_file %t/order %t/weak-common.o %t/defined.a %t/test.o -o %t/test | ||
| # RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=LARGER-COMMON | ||
|
|
||
| ## If an archive has both a common and a defined symbol, the defined one should | ||
| ## win. | ||
| # RUN: lld -flavor darwinnew -syslibroot %S/Inputs/MacOSX.sdk -lSystem -order_file %t/order %t/weak-defined-and-common.a %t/calls-foo.o -o %t/calls-foo | ||
| # RUN: llvm-objdump --syms %t/calls-foo | FileCheck %s --check-prefix=WEAK-DEFINED | ||
| # RUN: lld -flavor darwinnew -syslibroot %S/Inputs/MacOSX.sdk -lSystem -order_file %t/order %t/calls-foo.o %t/weak-defined-and-common.a -o %t/calls-foo | ||
| # RUN: llvm-objdump --syms %t/calls-foo | FileCheck %s --check-prefix=WEAK-DEFINED | ||
|
|
||
| ## Common symbols take precedence over dylib symbols. | ||
| # RUN: lld -flavor darwinnew -syslibroot %S/Inputs/MacOSX.sdk -lSystem -order_file %t/order %t/libfoo.dylib %t/weak-common.o %t/test.o -o %t/test | ||
| # RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=LARGER-COMMON | ||
| # RUN: lld -flavor darwinnew -syslibroot %S/Inputs/MacOSX.sdk -lSystem -order_file %t/order %t/weak-common.o %t/libfoo.dylib %t/test.o -o %t/test | ||
| # RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=LARGER-COMMON | ||
|
|
||
| # LARGER-COMMON-LABEL: SYMBOL TABLE: | ||
| # LARGER-COMMON-DAG: [[#%x, FOO_ADDR:]] g O __DATA,__common _foo | ||
| # LARGER-COMMON-DAG: [[#FOO_ADDR + 2]] g O __DATA,__common _foo_end | ||
|
|
||
| # DEFINED-LABEL: SYMBOL TABLE: | ||
| # DEFINED: g F __TEXT,__text _foo | ||
|
|
||
| # WEAK-DEFINED-LABEL: SYMBOL TABLE: | ||
| # WEAK-DEFINED: w F __TEXT,__text _foo | ||
|
|
||
| #--- order | ||
| ## %t/order is important as we determine the size of a given symbol via the | ||
| ## address of the next symbol. | ||
| _foo | ||
| _foo_end | ||
|
|
||
| #--- common.s | ||
| .comm _foo, 1 | ||
|
|
||
| .globl _bar | ||
| _bar: | ||
|
|
||
| #--- weak-common.s | ||
| .weak_definition _foo | ||
| .comm _foo, 2 | ||
|
|
||
| #--- defined.s | ||
| .globl _foo | ||
| _foo: | ||
| .quad 0x1234 | ||
|
|
||
| #--- weak-defined.s | ||
| .globl _foo | ||
| .weak_definition _foo | ||
| _foo: | ||
| .quad 0x1234 | ||
|
|
||
| #--- libfoo.s | ||
| .globl _foo | ||
| _foo: | ||
| .quad 0x1234 | ||
|
|
||
| #--- test.s | ||
| .comm _foo_end, 1 | ||
|
|
||
| .globl _main | ||
| _main: | ||
| ret | ||
|
|
||
| #--- calls-foo.s | ||
| .comm _foo_end, 1 | ||
|
|
||
| .globl _main | ||
| _main: | ||
| callq _foo | ||
| ret |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| # REQUIRES: x86 | ||
| # RUN: split-file %s %t | ||
| # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/libfoo.s -o %t/libfoo.o | ||
| # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/test.s -o %t/test.o | ||
| # RUN: lld -flavor darwinnew -dylib %t/libfoo.o -o %t/libfoo.dylib -syslibroot %S/Inputs/MacOSX.sdk -lSystem | ||
| # RUN: lld -flavor darwinnew %t/test.o %t/libfoo.dylib -o %t/test -syslibroot %S/Inputs/MacOSX.sdk -lSystem | ||
| # RUN: llvm-objdump --macho -d --no-show-raw-insn --indirect-symbols %t/test | FileCheck %s | ||
|
|
||
| # CHECK: (__TEXT,__text) section | ||
| # CHECK-NEXT: _main: | ||
| # CHECK-NEXT: movq {{.*}}(%rip), %rax ## literal pool symbol address: _foo | ||
| # CHECK-NEXT: movq {{.*}}(%rip), %rax ## literal pool symbol address: _bar | ||
| # CHECK-NEXT: movq {{.*}}(%rip), %rax ## literal pool symbol address: _foo_tlv | ||
| # CHECK-NEXT: movq {{.*}}(%rip), %rax ## literal pool symbol address: _bar_tlv | ||
| # CHECK-NEXT: callq {{.*}} ## symbol stub for: _foo_fn | ||
| # CHECK-NEXT: callq {{.*}} ## symbol stub for: _bar_fn | ||
| # CHECK-NEXT: retq | ||
|
|
||
| # CHECK: Indirect symbols for (__TEXT,__stubs) 2 entries | ||
| # CHECK-NEXT: address index name | ||
| # CHECK-NEXT: _bar_fn | ||
| # CHECK-NEXT: _foo_fn | ||
| # CHECK-NEXT: Indirect symbols for (__DATA,__thread_ptrs) 2 entries | ||
| # CHECK-NEXT: address index name | ||
| # CHECK-NEXT: _bar_tlv | ||
| # CHECK-NEXT: _foo_tlv | ||
| # CHECK-NEXT: Indirect symbols for (__DATA,__la_symbol_ptr) 2 entries | ||
| # CHECK-NEXT: address index name | ||
| # CHECK-NEXT: _bar_fn | ||
| # CHECK-NEXT: _foo_fn | ||
| # CHECK-NEXT: Indirect symbols for (__DATA_CONST,__got) 3 entries | ||
| # CHECK-NEXT: address index name | ||
| # CHECK-NEXT: _bar | ||
| # CHECK-NEXT: _foo | ||
| # CHECK-NEXT: _stub_binder | ||
|
|
||
| #--- libfoo.s | ||
|
|
||
| .globl _foo, _foo_fn, _bar, _bar_fn | ||
| _foo: | ||
| _foo_fn: | ||
| _bar: | ||
| _bar_fn: | ||
|
|
||
| .section __DATA,__thread_vars,thread_local_variables | ||
| .globl _foo_tlv, _bar_tlv | ||
| _foo_tlv: | ||
| _bar_tlv: | ||
|
|
||
| #--- test.s | ||
|
|
||
| .globl _main | ||
| _main: | ||
| movq _foo@GOTPCREL(%rip), %rax | ||
| movq _bar@GOTPCREL(%rip), %rax | ||
| mov _foo_tlv@TLVP(%rip), %rax | ||
| mov _bar_tlv@TLVP(%rip), %rax | ||
| callq _foo_fn | ||
| callq _bar_fn | ||
| ret |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # REQUIRES: x86 | ||
| # RUN: split-file %s %t | ||
| # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/test.s -o %t/test.o | ||
| # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/foo.s -o %t/foo.o | ||
| # RUN: lld -flavor darwinnew -syslibroot %S/Inputs/MacOSX.sdk -lSystem -dylib %t/foo.o -o %t/libfoo.dylib | ||
|
|
||
| # RUN: lld -flavor darwinnew -syslibroot %S/Inputs/MacOSX.sdk -weak-lSystem %t/test.o -weak_framework CoreFoundation -weak_library %t/libfoo.dylib -o %t/test | ||
| # RUN: llvm-objdump --macho --all-headers %t/test | FileCheck %s -DDIR=%t | ||
|
|
||
| # CHECK: cmd LC_LOAD_WEAK_DYLIB | ||
| # CHECK-NEXT: cmdsize | ||
| # CHECK-NEXT: name /usr/lib/libSystem.B.dylib | ||
|
|
||
| # CHECK: cmd LC_LOAD_WEAK_DYLIB | ||
| # CHECK-NEXT: cmdsize | ||
| # CHECK-NEXT: name /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation | ||
|
|
||
| # CHECK: cmd LC_LOAD_WEAK_DYLIB | ||
| # CHECK-NEXT: cmdsize | ||
| # CHECK-NEXT: name [[DIR]]/libfoo.dylib | ||
|
|
||
| #--- foo.s | ||
| .globl _foo | ||
| _foo: | ||
| ret | ||
|
|
||
| #--- test.s | ||
| .globl _main | ||
| .text | ||
| _main: | ||
| ret |