diff options
Diffstat (limited to 'lld/test')
38 files changed, 1267 insertions, 117 deletions
diff --git a/lld/test/COFF/Inputs/loadconfig-arm64.s b/lld/test/COFF/Inputs/loadconfig-arm64.s new file mode 100644 index 000000000000..67d1a0aea50e --- /dev/null +++ b/lld/test/COFF/Inputs/loadconfig-arm64.s @@ -0,0 +1,15 @@ + .section .rdata,"dr" + .globl _load_config_used + .p2align 3, 0 +_load_config_used: + .word 0x140 + .fill 0x7c,1,0 + .xword __guard_fids_table + .xword __guard_fids_count + .xword __guard_flags + .xword 0 + .xword __guard_iat_table + .xword __guard_iat_count + .xword __guard_longjmp_table + .xword __guard_longjmp_count + .fill 0x80,1,0 diff --git a/lld/test/COFF/Inputs/start-lib1.ll b/lld/test/COFF/Inputs/start-lib1.ll deleted file mode 100644 index 3d4fe19daab9..000000000000 --- a/lld/test/COFF/Inputs/start-lib1.ll +++ /dev/null @@ -1,13 +0,0 @@ -target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" -target triple = "x86_64-pc-windows-msvc" - -declare i32 @bar() - -define i32 @foo() { - %1 = call i32 () @bar() - %2 = add i32 %1, 1 - ret i32 %2 -} - -!llvm.linker.options = !{!0} -!0 = !{!"/INCLUDE:foo"} diff --git a/lld/test/COFF/Inputs/start-lib2.ll b/lld/test/COFF/Inputs/start-lib2.ll deleted file mode 100644 index 830ec1d6d191..000000000000 --- a/lld/test/COFF/Inputs/start-lib2.ll +++ /dev/null @@ -1,9 +0,0 @@ -target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" -target triple = "x86_64-pc-windows-msvc" - -define i32 @bar() { - ret i32 1 -} - -!llvm.linker.options = !{!0} -!0 = !{!"/INCLUDE:bar"} diff --git a/lld/test/COFF/arm64ec-codemap.test b/lld/test/COFF/arm64ec-codemap.test index 6e97c14e87d8..050261117be2 100644 --- a/lld/test/COFF/arm64ec-codemap.test +++ b/lld/test/COFF/arm64ec-codemap.test @@ -9,6 +9,7 @@ RUN: llvm-mc -filetype=obj -triple=arm64ec-windows data-sec2.s -o data-sec2.obj RUN: llvm-mc -filetype=obj -triple=arm64ec-windows empty-sec.s -o arm64ec-empty-sec.obj RUN: llvm-mc -filetype=obj -triple=x86_64-windows x86_64-func-sym.s -o x86_64-func-sym.obj RUN: llvm-mc -filetype=obj -triple=x86_64-windows empty-sec.s -o x86_64-empty-sec.obj +RUN: llvm-mc -filetype=obj -triple=aarch64-windows %S/Inputs/loadconfig-arm64.s -o loadconfig-arm64.obj RUN: llvm-mc -filetype=obj -triple=arm64ec-windows %S/Inputs/loadconfig-arm64ec.s -o loadconfig-arm64ec.obj Link ARM64EC DLL and verify that the code is arranged as expected. @@ -51,7 +52,7 @@ RUN: llvm-readobj --coff-load-config test2.dll | FileCheck -check-prefix=CODEMAP RUN: llvm-objdump -d test2.dll | FileCheck -check-prefix=DISASM %s RUN: lld-link -out:testx.dll -machine:arm64x arm64-func-sym.obj arm64ec-func-sym.obj \ -RUN: x86_64-func-sym.obj loadconfig-arm64ec.obj -dll -noentry +RUN: x86_64-func-sym.obj loadconfig-arm64.obj loadconfig-arm64ec.obj -dll -noentry Adding empty chunks does not affect code map ranges. diff --git a/lld/test/COFF/arm64ec-entry-thunk.s b/lld/test/COFF/arm64ec-entry-thunk.s index 164e6cc43964..b31d315eeb7a 100644 --- a/lld/test/COFF/arm64ec-entry-thunk.s +++ b/lld/test/COFF/arm64ec-entry-thunk.s @@ -27,6 +27,7 @@ thunk: .rva func // RUN: llvm-mc -filetype=obj -triple=arm64ec-windows %S/Inputs/loadconfig-arm64ec.s -o loadcfg.obj +// RUN: llvm-mc -filetype=obj -triple=aarch64-windows %S/Inputs/loadconfig-arm64.s -o native-loadcfg.obj // RUN: llvm-mc -filetype=obj -triple=arm64ec-windows test-simple.s -o test-simple.obj // RUN: lld-link -machine:arm64ec -dll -noentry -out:out-simple.dll loadcfg.obj test-simple.obj // RUN: llvm-objdump -d out-simple.dll | FileCheck --check-prefix=DISASM %s @@ -43,7 +44,7 @@ thunk: // RUN: llvm-readobj --sections out-simple.dll | FileCheck --check-prefix=HYBMP %s // HYBMP-NOT: .hybmp -// RUN: lld-link -machine:arm64x -dll -noentry -out:out-simplex.dll loadcfg.obj test-simple.obj +// RUN: lld-link -machine:arm64x -dll -noentry -out:out-simplex.dll native-loadcfg.obj loadcfg.obj test-simple.obj // RUN: llvm-objdump -d out-simplex.dll | FileCheck --check-prefix=DISASM %s #--- test-split-func.s diff --git a/lld/test/COFF/arm64ec-lib.test b/lld/test/COFF/arm64ec-lib.test index 9dff23022f9e..8698a5ceccbe 100644 --- a/lld/test/COFF/arm64ec-lib.test +++ b/lld/test/COFF/arm64ec-lib.test @@ -11,6 +11,7 @@ RUN: llvm-mc -filetype=obj -triple=arm64ec-windows ref-alias.s -o ref-alias.obj RUN: llvm-mc -filetype=obj -triple=arm64ec-windows ref-thunk.s -o ref-thunk.obj RUN: llvm-mc -filetype=obj -triple=arm64ec-windows func.s -o func.obj RUN: llvm-mc -filetype=obj -triple=x86_64-windows func-x86_64.s -o func-x86_64.obj +RUN: llvm-mc -filetype=obj -triple=aarch64-windows %S/Inputs/loadconfig-arm64.s -o loadconfig-arm64.obj RUN: llvm-mc -filetype=obj -triple=arm64ec-windows %S/Inputs/loadconfig-arm64ec.s -o loadconfig-arm64ec.obj RUN: llvm-lib -machine:arm64ec -out:sym-arm64ec.lib sym-arm64ec.obj nsym-aarch64.obj @@ -26,7 +27,8 @@ Verify that a symbol can be referenced from a regular archive map when ECSYMBOLS RUN: lld-link -machine:arm64ec -dll -noentry -out:test2.dll symref-arm64ec.obj sym-x86_64.lib loadconfig-arm64ec.obj Verify that both native and EC symbols can be referenced in a hybrid target. -RUN: lld-link -machine:arm64x -dll -noentry -out:test3.dll symref-arm64ec.obj nsymref-aarch64.obj sym-arm64ec.lib loadconfig-arm64ec.obj +RUN: lld-link -machine:arm64x -dll -noentry -out:test3.dll symref-arm64ec.obj nsymref-aarch64.obj sym-arm64ec.lib \ +RUN: loadconfig-arm64.obj loadconfig-arm64ec.obj Ensure that an EC symbol is not resolved using a regular symbol map. RUN: not lld-link -machine:arm64ec -dll -noentry -out:test-err.dll nsymref-arm64ec.obj sym-arm64ec.lib loadconfig-arm64ec.obj 2>&1 |\ diff --git a/lld/test/COFF/arm64ec-range-thunks.s b/lld/test/COFF/arm64ec-range-thunks.s index f170349d7965..dcfa6365b4e3 100644 --- a/lld/test/COFF/arm64ec-range-thunks.s +++ b/lld/test/COFF/arm64ec-range-thunks.s @@ -5,6 +5,7 @@ # RUN: llvm-mc -filetype=obj -triple=aarch64-windows native-funcs.s -o funcs-aarch64.obj # RUN: llvm-mc -filetype=obj -triple=x86_64-windows space.s -o space-x86_64.obj # RUN: llvm-mc -filetype=obj -triple=aarch64-windows space.s -o space-aarch64.obj +# RUN: llvm-mc -filetype=obj -triple=aarch64-windows %S/Inputs/loadconfig-arm64.s -o loadconfig-arm64.obj # RUN: llvm-mc -filetype=obj -triple=arm64ec-windows %S/Inputs/loadconfig-arm64ec.s -o loadconfig-arm64ec.obj @@ -59,8 +60,8 @@ # A similar test using a hybrid binary and native placeholder chunks. -# RUN: lld-link -machine:arm64x -noentry -dll funcs-arm64ec.obj space-aarch64.obj loadconfig-arm64ec.obj -out:testx.dll \ -# RUN: -verbose 2>&1 | FileCheck -check-prefix=VERBOSE %s +# RUN: lld-link -machine:arm64x -noentry -dll funcs-arm64ec.obj space-aarch64.obj loadconfig-arm64.obj loadconfig-arm64ec.obj \ +# RUN: -out:testx.dll -verbose 2>&1 | FileCheck -check-prefix=VERBOSE %s # RUN: llvm-objdump -d testx.dll | FileCheck --check-prefix=DISASM %s # RUN: llvm-readobj --coff-load-config testx.dll | FileCheck --check-prefix=LOADCFGX %s @@ -74,8 +75,8 @@ # Test a hybrid ARM64X binary which requires range extension thunks for both native and EC relocations. -# RUN: lld-link -machine:arm64x -noentry -dll funcs-arm64ec.obj funcs-aarch64.obj loadconfig-arm64ec.obj -out:testx2.dll \ -# RUN: -verbose 2>&1 | FileCheck -check-prefix=VERBOSEX %s +# RUN: lld-link -machine:arm64x -noentry -dll funcs-arm64ec.obj funcs-aarch64.obj loadconfig-arm64.obj loadconfig-arm64ec.obj \ +# RUN: -out:testx2.dll -verbose 2>&1 | FileCheck -check-prefix=VERBOSEX %s # VERBOSEX: Added 5 thunks with margin {{.*}} in 1 passes # RUN: llvm-objdump -d testx2.dll | FileCheck --check-prefix=DISASMX %s diff --git a/lld/test/COFF/arm64x-loadconfig.s b/lld/test/COFF/arm64x-loadconfig.s new file mode 100644 index 000000000000..d21f4bfe95b8 --- /dev/null +++ b/lld/test/COFF/arm64x-loadconfig.s @@ -0,0 +1,193 @@ +// REQUIRES: aarch64 +// RUN: split-file %s %t.dir && cd %t.dir + +// RUN: llvm-mc -filetype=obj -triple=aarch64-windows test.s -o test.obj +// RUN: llvm-mc -filetype=obj -triple=arm64ec-windows chpe.s -o chpe.obj +// RUN: llvm-mc -filetype=obj -triple=aarch64-windows loadconfig.s -o loadconfig.obj +// RUN: llvm-mc -filetype=obj -triple=arm64ec-windows loadconfig-ec.s -o loadconfig-ec.obj +// RUN: llvm-mc -filetype=obj -triple=aarch64-windows loadconfig-short.s -o loadconfig-short.obj +// RUN: llvm-mc -filetype=obj -triple=arm64ec-windows loadconfig-short.s -o loadconfig-short-arm64ec.obj + +// RUN: lld-link -machine:arm64x -out:out-warn.dll -dll -noentry test.obj \ +// RUN: 2>&1 | FileCheck --check-prefixes=WARN-LOADCFG,WARN-EC-LOADCFG %s +// WARN-LOADCFG: lld-link: warning: native version of '_load_config_used' is missing for ARM64X target +// WARN-EC-LOADCFG: lld-link: warning: EC version of '_load_config_used' is missing + +// RUN: lld-link -machine:arm64x -out:out-nonative.dll -dll -noentry loadconfig-ec.obj chpe.obj \ +// RUN: 2>&1 | FileCheck --check-prefixes=WARN-LOADCFG --implicit-check-not EC %s + +// RUN: lld-link -machine:arm64ec -out:out-ec.dll -dll -noentry chpe.obj \ +// RUN: 2>&1 | FileCheck --check-prefixes=WARN-EC-LOADCFG --implicit-check-not native %s + +// RUN: lld-link -machine:arm64x -out:out.dll -dll -noentry loadconfig.obj test.obj \ +// RUN: 2>&1 | FileCheck --check-prefixes=WARN-EC-LOADCFG --implicit-check-not native %s + +// RUN: llvm-readobj --coff-load-config out.dll | FileCheck --check-prefix=DYNRELOCS %s +// DYNRELOCS: DynamicValueRelocTableOffset: 0xC +// DYNRELOCS-NEXT: DynamicValueRelocTableSection: 4 +// DYNRELOCS: DynamicRelocations [ +// DYNRELOCS-NEXT: Version: 0x1 +// DYNRELOCS-NEXT: Arm64X [ +// DYNRELOCS-NEXT: Entry [ +// DYNRELOCS-NEXT: RVA: 0x7C +// DYNRELOCS-NEXT: Type: VALUE +// DYNRELOCS-NEXT: Size: 0x2 +// DYNRELOCS-NEXT: Value: 0x8664 +// DYNRELOCS-NEXT: ] +// DYNRELOCS-NEXT: Entry [ +// DYNRELOCS-NEXT: RVA: 0x150 +// DYNRELOCS-NEXT: Type: VALUE +// DYNRELOCS-NEXT: Size: 0x4 +// DYNRELOCS-NEXT: Value: 0x0 +// DYNRELOCS-NEXT: ] +// DYNRELOCS-NEXT: Entry [ +// DYNRELOCS-NEXT: RVA: 0x154 +// DYNRELOCS-NEXT: Type: VALUE +// DYNRELOCS-NEXT: Size: 0x4 +// DYNRELOCS-NEXT: Value: 0x0 +// DYNRELOCS-NEXT: ] +// DYNRELOCS-NEXT: ] +// DYNRELOCS-NEXT: ] + +// RUN: llvm-readobj --headers out.dll | FileCheck --check-prefix=HEADERS %s +// HEADERS: BaseRelocationTableRVA: 0x4000 +// HEADERS-NEXT: BaseRelocationTableSize: 0xC +// HEADERS: LoadConfigTableRVA: 0x1000 +// HEADERS-NEXT: LoadConfigTableSize: 0x140 +// HEADERS: Name: .reloc (2E 72 65 6C 6F 63 00 00) +// HEADERS-NEXT: VirtualSize: 0x38 + +// RUN: lld-link -machine:arm64x -out:out-short.dll -dll -noentry loadconfig-short.obj 2>&1 | FileCheck --check-prefix=WARN-RELOC-SIZE %s +// RUN: lld-link -machine:arm64x -out:out-short.dll -dll -noentry loadconfig-short-arm64ec.obj 2>&1 | FileCheck --check-prefix=WARN-RELOC-SIZE %s +// WARN-RELOC-SIZE: lld-link: warning: '_load_config_used' structure too small to include dynamic relocations + +// Check that the CHPE metadata pointer is correctly copied from the EC load config to the native load config. + +// RUN: lld-link -machine:arm64x -out:out-hyb.dll -dll -noentry loadconfig.obj loadconfig-ec.obj chpe.obj test.obj + +// RUN: llvm-readobj --coff-load-config out-hyb.dll | FileCheck --check-prefix=LOADCFG %s +// LOADCFG: Format: COFF-ARM64X +// LOADCFG-NEXT: Arch: aarch64 +// LOADCFG-NEXT: AddressSize: 64bit +// LOADCFG-NEXT: LoadConfig [ +// LOADCFG-NEXT: Size: 0x140 +// LOADCFG: CHPEMetadata [ +// LOADCFG-NEXT: Version: 0x2 +// LOADCFG: RedirectionMetadata: 12288 +// LOADCFG: AlternateEntryPoint: 0x0 +// LOADCFG-NEXT: AuxiliaryIAT: 0x0 +// LOADCFG-NEXT: GetX64InformationFunctionPointer: 0x0 +// LOADCFG-NEXT: SetX64InformationFunctionPointer: 0x0 +// LOADCFG-NEXT: ExtraRFETable: 0x0 +// LOADCFG-NEXT: ExtraRFETableSize: 0x0 +// LOADCFG-NEXT: __os_arm64x_dispatch_fptr: 0x0 +// LOADCFG-NEXT: AuxiliaryIATCopy: 0x0 +// LOADCFG-NEXT: AuxiliaryDelayloadIAT: 0x0 +// LOADCFG-NEXT: AuxiliaryDelayloadIATCopy: 0x0 +// LOADCFG-NEXT: HybridImageInfoBitfield: 0x0 +// LOADCFG: ] +// LOADCFG-NEXT: DynamicRelocations [ +// LOADCFG-NEXT: Version: 0x1 +// LOADCFG-NEXT: Arm64X [ +// LOADCFG-NEXT: Entry [ +// LOADCFG-NEXT: RVA: 0x7C +// LOADCFG-NEXT: Type: VALUE +// LOADCFG-NEXT: Size: 0x2 +// LOADCFG-NEXT: Value: 0x8664 +// LOADCFG-NEXT: ] +// LOADCFG-NEXT: Entry [ +// LOADCFG-NEXT: RVA: 0x150 +// LOADCFG-NEXT: Type: VALUE +// LOADCFG-NEXT: Size: 0x4 +// LOADCFG-NEXT: Value: 0x0 +// LOADCFG-NEXT: ] +// LOADCFG-NEXT: Entry [ +// LOADCFG-NEXT: RVA: 0x154 +// LOADCFG-NEXT: Type: VALUE +// LOADCFG-NEXT: Size: 0x4 +// LOADCFG-NEXT: Value: 0x0 +// LOADCFG-NEXT: ] +// LOADCFG-NEXT: ] +// LOADCFG-NEXT: ] +// LOADCFG-NEXT: HybridObject { +// LOADCFG-NEXT: Format: COFF-x86-64 +// LOADCFG-NEXT: Arch: x86_64 +// LOADCFG-NEXT: AddressSize: 64bit + +// RUN: llvm-readobj --coff-basereloc out-hyb.dll | FileCheck --check-prefix=BASERELOC %s +// BASERELOC: BaseReloc [ +// BASERELOC-NEXT: Entry { +// BASERELOC-NEXT: Type: DIR64 +// BASERELOC-NEXT: Address: 0x1208 +// BASERELOC-NEXT: } +// BASERELOC-NEXT: Entry { +// BASERELOC: Type: DIR64 +// BASERELOC-NEXT: Address: 0x2074 +// BASERELOC-NEXT: } + +#--- test.s + .data +sym: + // Emit a basereloc to make the loadconfig test more meaningful. + .xword sym + +#--- loadconfig.s + .section .rdata,"dr" + .globl _load_config_used + .p2align 3, 0 +_load_config_used: + .word 0x140 + .fill 0x13c,1,0 + +#--- loadconfig-ec.s + .section .rdata,"dr" + .globl _load_config_used + .p2align 3, 0 +_load_config_used: + .word 0x140 + .fill 0xc4,1,0 + .xword __chpe_metadata + .fill 0x70,1,0 + +#--- loadconfig-short.s + .section .rdata,"dr" + .globl _load_config_used + .p2align 3, 0 +_load_config_used: + .word 0xe4 + .fill 0xe0,1,0 + +#--- chpe.s + .data + .globl __chpe_metadata + .p2align 3, 0 +__chpe_metadata: + .word 2 + .rva __hybrid_code_map + .word __hybrid_code_map_count + .rva __x64_code_ranges_to_entry_points + .rva __arm64x_redirection_metadata + .word 0 // __os_arm64x_dispatch_call_no_redirect + .word 0 // __os_arm64x_dispatch_ret + .word 0 // __os_arm64x_check_call + .word 0 // __os_arm64x_check_icall + .word 0 // __os_arm64x_check_icall_cfg + .rva __arm64x_native_entrypoint + .rva __hybrid_auxiliary_iat + .word __x64_code_ranges_to_entry_points_count + .word __arm64x_redirection_metadata_count + .word 0 // __os_arm64x_get_x64_information + .word 0 // __os_arm64x_set_x64_information + .rva __arm64x_extra_rfe_table + .word __arm64x_extra_rfe_table_size + .word 0 // __os_arm64x_dispatch_fptr + .rva __hybrid_auxiliary_iat_copy + .rva __hybrid_auxiliary_delayload_iat + .rva __hybrid_auxiliary_delayload_iat_copy + .word __hybrid_image_info_bitfield + .word 0 // __os_arm64x_helper3 + .word 0 // __os_arm64x_helper4 + .word 0 // __os_arm64x_helper5 + .word 0 // __os_arm64x_helper6 + .word 0 // __os_arm64x_helper7 + .word 0 // __os_arm64x_helper8 diff --git a/lld/test/COFF/arm64x-symtab.s b/lld/test/COFF/arm64x-symtab.s new file mode 100644 index 000000000000..2b269dde61f6 --- /dev/null +++ b/lld/test/COFF/arm64x-symtab.s @@ -0,0 +1,51 @@ +// REQUIRES: aarch64, x86 +// RUN: split-file %s %t.dir && cd %t.dir + +// RUN: llvm-mc -filetype=obj -triple=aarch64-windows sym.s -o sym-aarch64.obj +// RUN: llvm-mc -filetype=obj -triple=arm64ec-windows sym.s -o sym-arm64ec.obj +// RUN: llvm-mc -filetype=obj -triple=x86_64-windows sym.s -o sym-x86_64.obj +// RUN: llvm-mc -filetype=obj -triple=aarch64-windows symref.s -o symref-aarch64.obj +// RUN: llvm-mc -filetype=obj -triple=arm64ec-windows symref.s -o symref-arm64ec.obj +// RUN: llvm-mc -filetype=obj -triple=x86_64-windows symref.s -o symref-x86_64.obj +// RUN: llvm-lib -machine:arm64x -out:sym.lib sym-aarch64.obj sym-arm64ec.obj + +// Check that native object files can't reference EC symbols. + +// RUN: not lld-link -machine:arm64x -dll -noentry -out:err1.dll symref-aarch64.obj sym-arm64ec.obj \ +// RUN: 2>&1 | FileCheck --check-prefix=UNDEF %s +// UNDEF: lld-link: error: undefined symbol: sym +// UNDEF-NEXT: >>> referenced by symref-aarch64.obj:(.data) + +// Check that EC object files can't reference native symbols. + +// RUN: not lld-link -machine:arm64x -dll -noentry -out:out.dll symref-arm64ec.obj sym-aarch64.obj \ +// RUN: 2>&1 | FileCheck --check-prefix=UNDEFEC %s +// UNDEFEC: lld-link: error: undefined symbol: sym +// UNDEFEC-NEXT: >>> referenced by symref-arm64ec.obj:(.data) + +// RUN: not lld-link -machine:arm64x -dll -noentry -out:out.dll symref-x86_64.obj sym-aarch64.obj \ +// RUN: 2>&1 | FileCheck --check-prefix=UNDEFX86 %s +// UNDEFX86: lld-link: error: undefined symbol: sym +// UNDEFX86-NEXT: >>> referenced by symref-x86_64.obj:(.data) + +// RUN: not lld-link -machine:arm64x -dll -noentry -out:err2.dll symref-aarch64.obj sym-x86_64.obj \ +// RUN: 2>&1 | FileCheck --check-prefix=UNDEF %s + +// Check that ARM64X target can have the same symbol names in both native and EC namespaces. + +// RUN: lld-link -machine:arm64x -dll -noentry -out:out.dll symref-aarch64.obj sym-aarch64.obj \ +// RUN: symref-arm64ec.obj sym-x86_64.obj + +// Check that ARM64X target can reference both native and EC symbols from an archive. + +// RUN: lld-link -machine:arm64x -dll -noentry -out:out2.dll symref-aarch64.obj symref-arm64ec.obj sym.lib + +#--- symref.s + .data + .rva sym + +#--- sym.s + .data + .globl sym +sym: + .word 0 diff --git a/lld/test/COFF/dependentflags.test b/lld/test/COFF/dependentflags.test index 3e90511591c7..2ea974c268d5 100644 --- a/lld/test/COFF/dependentflags.test +++ b/lld/test/COFF/dependentflags.test @@ -20,6 +20,10 @@ RUN: not lld-link %S/Inputs/precomp-a.obj %t.ldcfg.obj /out:%t.exe /nodefaultlib RUN: not lld-link %S/Inputs/precomp-a.obj %t.ldcfg.obj /out:%t.exe /nodefaultlib /force /dependentloadflag:zz 2>&1 | FileCheck %s --check-prefix FAIL RUN: not lld-link %S/Inputs/precomp-a.obj %t.ldcfg.obj /out:%t.exe /nodefaultlib /force /dependentloadflag:0xf0000 2>&1 | FileCheck %s --check-prefix FAIL-RANGE +// ---- Warn if _load_config_used is missing +RUN: llvm-lib %t.ldcfg.obj /out:%t.lib +RUN: lld-link %S/Inputs/precomp-a.obj /out:%t.exe /nodefaultlib /force /dependentloadflag:0x800 2>&1 | FileCheck %s --check-prefix WARN-NOBASE +RUN: lld-link %S/Inputs/precomp-a.obj %t.lib /out:%t.exe /nodefaultlib /force /dependentloadflag:0x800 2>&1 | FileCheck %s --allow-empty --check-prefix NO-WARN BASE: DependentLoadFlags: 0x0 FLAGS-800: DependentLoadFlags: 0x800 @@ -29,3 +33,5 @@ FAIL: lld-link: error: /dependentloadflag: invalid argument: zz FAIL-RANGE: lld-link: error: /dependentloadflag: invalid argument: 0xf0000 FAIL-NOARG: lld-link: error: /dependentloadflag: no argument specified +WARN-NOBASE: lld-link: warning: _load_config_used not found, /dependentloadflag will have no effect +NO-WARN-NOT: lld-link: warning: _load_config_used not found, /dependentloadflag will have no effect diff --git a/lld/test/COFF/guard-warnings.s b/lld/test/COFF/guard-warnings.s index 77448ee95c00..092871597d1f 100644 --- a/lld/test/COFF/guard-warnings.s +++ b/lld/test/COFF/guard-warnings.s @@ -38,7 +38,7 @@ # RUN: llvm-mc -triple x86_64-windows-msvc %t/loadcfg-misaligned2.s -filetype=obj -o %t/loadcfg-misaligned2.obj # RUN: lld-link %t/main.obj %t/loadcfg-misaligned2.obj -guard:cf,longjmp,ehcont -out:%t-misaligned2.exe -entry:main %basename_t-exp.lib 2>&1 | FileCheck %s --check-prefix=WARN_ALIGN2 -# WARN_ALIGN2: warning: '_load_config_used' is misaligned (RVA is 0x{{[0-9A-F]*}}2 not aligned to 8 bytes) +# WARN_ALIGN2: warning: '_load_config_used' is misaligned (section offset is 0x{{[0-9A-F]*}}2 not aligned to 8 bytes) # RUN: llvm-mc -triple x86_64-windows-msvc %t/loadcfg-full.s -filetype=obj -o %t/loadcfg-full.obj # RUN: lld-link %t/main.obj %t/loadcfg-full.obj -guard:cf,longjmp,ehcont -out:%t.exe -entry:main %basename_t-exp.lib 2>&1 | FileCheck %s --check-prefix=NOWARN --allow-empty diff --git a/lld/test/COFF/linkrepro.test b/lld/test/COFF/linkrepro.test index d5a34a201a5d..a5779a9ec82e 100644 --- a/lld/test/COFF/linkrepro.test +++ b/lld/test/COFF/linkrepro.test @@ -1,7 +1,10 @@ # REQUIRES: x86, shell # RUN: rm -rf %t.dir +# RUN: split-file %s %t.dir + # RUN: yaml2obj %p/Inputs/hello32.yaml -o %t.obj +# RUN: llvm-mc -filetype=obj -triple=i386-windows %t.dir/drectve.s -o %t.dir/drectve.obj # RUN: echo '_main@0' > %t.order # RUN: touch %t.def # RUN: touch %t.cg @@ -46,7 +49,7 @@ and various other flags. # RUN: diff %t.order repro/%:t.order # RUN: diff %t.def repro/%:t.def # RUN: diff %p/Inputs/std32.lib repro/%:p/Inputs/std32.lib -# RUN: FileCheck %s --check-prefix=RSP < repro/response.txt +# RUN: FileCheck %s --check-prefix=RSP-DEFAULTLIB < repro/response.txt # RUN: cd repro; lld-link @response.txt Test adding .lib files with LIB env var to repro archive, @@ -61,7 +64,7 @@ and various other flags. # RUN: diff %t.order repro/%:t.order # RUN: diff %t.def repro/%:t.def # RUN: diff %p/Inputs/std32.lib repro/%:p/Inputs/std32.lib -# RUN: FileCheck %s --check-prefix=RSP < repro/response.txt +# RUN: FileCheck %s --check-prefix=RSP-DEFAULTLIB < repro/response.txt # RUN: cd repro; lld-link @response.txt # LIST: .obj @@ -70,14 +73,21 @@ and various other flags. # LIST: .def # LIST: .order +# RSP: linkrepro.test.tmp.obj +# RSP: std32.lib # RSP: /subsystem:console # RSP: /entry:main@0 # RSP: /out: # RSP-NOT: /order:@/ # RSP-NOT: /def:/ -# RSP: linkrepro.test.tmp.obj -# RSP-NOT: defaultlib -# RSP: std32.lib + +# RSP-DEFAULTLIB: linkrepro.test.tmp.obj +# RSP-DEFAULTLIB: /defaultlib:std32 +# RSP-DEFAULTLIB: /subsystem:console +# RSP-DEFAULTLIB: /entry:main@0 +# RSP-DEFAULTLIB: /out: +# RSP-DEFAULTLIB-NOT: /order:@/ +# RSP-DEFAULTLIB-NOT: /def:/ Test /call-graph-ordering-file (can't be used with /order:, needs separate test) # RUN: mkdir -p %t.dir/build5 @@ -96,3 +106,90 @@ Test /call-graph-ordering-file (can't be used with /order:, needs separate test) # LISTCG: .cg # RSPCG-NOT: /call-graph-ordering-file:/ + +Test /defaultlib: from a .drectve section +# RUN: mkdir -p %t.dir/build6 +# RUN: cd %t.dir/build6 +# RUN: lld-link %t.obj %t.dir/drectve.obj /libpath:%p/Inputs /subsystem:console \ +# RUN: /entry:main@0 /linkrepro:. -safeseh:no /out:%t.exe /order:@%t.order /def:%t.def +# RUN: tar tf repro.tar | FileCheck --check-prefix=LIST %s +# RUN: tar xf repro.tar +# RUN: diff %t.obj repro/%:t.obj +# RUN: diff %t.order repro/%:t.order +# RUN: diff %t.def repro/%:t.def +# RUN: diff %p/Inputs/std32.lib repro/%:p/Inputs/std32.lib +# RUN: FileCheck %s --check-prefix=RSP-DRECTVE < repro/response.txt +# RUN: cd repro; lld-link @response.txt + +# RSP-DRECTVE: linkrepro.test.tmp.obj +# RSP-DRECTVE: drectve.obj +# RSP-DRECTVE: /subsystem:console +# RSP-DRECTVE: /entry:main@0 +# RSP-DRECTVE: -safeseh:no +# RSP-DRECTVE: /out: + +Test /wholearchive: with /linkrepro: +# RUN: llvm-mc -filetype=obj -triple=i386-windows %t.dir/archive.s -o %t.dir/archive.obj +# RUN: rm -f %t.dir/build7/archive.lib +# RUN: llvm-ar rcs %t.dir/archive.lib %t.dir/archive.obj +# RUN: mkdir -p %t.dir/build7 +# RUN: cd %t.dir/build7 + RUN: lld-link %t.obj /defaultlib:std32 /libpath:%p/Inputs /subsystem:console \ +# RUN: /entry:main@0 /linkrepro:. -safeseh:no /wholearchive:%t.dir/archive.lib \ +# RUN: /out:%t.exe /order:@%t.order /def:%t.def +# RUN: tar tf repro.tar | FileCheck --check-prefix=LIST %s +# RUN: tar xf repro.tar +# RUN: diff %t.obj repro/%:t.obj +# RUN: diff %t.order repro/%:t.order +# RUN: diff %t.def repro/%:t.def +# RUN: diff %p/Inputs/std32.lib repro/%:p/Inputs/std32.lib +# RUN: FileCheck %s --check-prefix=RSP-WHOLEARCHIVE < repro/response.txt +# RUN: cd repro; lld-link @response.txt + +# RSP-WHOLEARCHIVE: linkrepro.test.tmp.obj +# RSP-WHOLEARCHIVE: /defaultlib:std32 +# RSP-WHOLEARCHIVE: /subsystem:console +# RSP-WHOLEARCHIVE: /entry:main@0 +# RSP-WHOLEARCHIVE: -safeseh:no +# RSP-WHOLEARCHIVE: /wholearchive:{{.*}}archive.lib +# RSP-WHOLEARCHIVE: /out: + +Test /start-lib / /end-lib with /linkrepro: +# RUN: mkdir -p %t.dir/build8 +# RUN: cd %t.dir/build8 +# RUN: lld-link %t.obj /defaultlib:std32 /libpath:%p/Inputs /subsystem:console \ +# RUN: /entry:main@0 /linkrepro:. -safeseh:no /start-lib %t.dir/drectve.obj /end-lib \ +# RUN: /out:%t.exe /order:@%t.order /def:%t.def +# RUN: tar tf repro.tar | FileCheck --check-prefix=LIST %s +# RUN: tar xf repro.tar +# RUN: diff %t.obj repro/%:t.obj +# RUN: diff %t.order repro/%:t.order +# RUN: diff %t.def repro/%:t.def +# RUN: diff %p/Inputs/std32.lib repro/%:p/Inputs/std32.lib +# RUN: FileCheck %s --check-prefix=RSP-STARTLIB < repro/response.txt +# RUN: cd repro; lld-link @response.txt + +# RSP-STARTLIB: linkrepro.test.tmp.obj +# RSP-STARTLIB: /defaultlib:std32 +# RSP-STARTLIB: /subsystem:console +# RSP-STARTLIB: /entry:main@0 +# RSP-STARTLIB: -safeseh:no +# RSP-STARTLIB: /start-lib +# RSP-STARTLIB-NEXT: drectve.obj +# RSP-STARTLIB-NEXT: /end-lib +# RSP-STARTLIB: /out: + +#--- drectve.s + .section .drectve, "yn" + .ascii "/defaultlib:std32" + +#--- archive.s + .text + .intel_syntax noprefix + .globl exportfn3 + .p2align 4 +exportfn3: + ret + + .section .drectve,"yni" + .ascii " /EXPORT:exportfn3" diff --git a/lld/test/COFF/loadcfg-short.test b/lld/test/COFF/loadcfg-short.test new file mode 100644 index 000000000000..dd4d4389ddc1 --- /dev/null +++ b/lld/test/COFF/loadcfg-short.test @@ -0,0 +1,33 @@ +# RUN: yaml2obj %s -o %t.obj +# RUN: not lld-link -out:%t.dll %t.obj -dll -noentry 2>&1 | FileCheck %s +# CHECK: lld-link: error: _load_config_used section chunk is too small + +--- !COFF +header: + Machine: IMAGE_FILE_MACHINE_AMD64 + Characteristics: [] +sections: + - Name: .rdata + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ] + Alignment: 16 + SectionData: '030000' +symbols: + - Name: .rdata + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 112 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 3 + - Name: _load_config_used + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL +... diff --git a/lld/test/COFF/loadcfg-size.test b/lld/test/COFF/loadcfg-size.test new file mode 100644 index 000000000000..871590f2328b --- /dev/null +++ b/lld/test/COFF/loadcfg-size.test @@ -0,0 +1,33 @@ +# RUN: yaml2obj %s -o %t.obj +# RUN: not lld-link -out:%t.dll %t.obj -dll -noentry 2>&1 | FileCheck %s +# CHECK: lld-link: error: _load_config_used specifies a size larger than its containing section chunk + +--- !COFF +header: + Machine: IMAGE_FILE_MACHINE_AMD64 + Characteristics: [] +sections: + - Name: .rdata + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ] + Alignment: 16 + SectionData: '0c00000000000000' +symbols: + - Name: .rdata + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 112 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 3 + - Name: _load_config_used + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL +... diff --git a/lld/test/COFF/loadcfg-uninitialized.test b/lld/test/COFF/loadcfg-uninitialized.test new file mode 100644 index 000000000000..5f956bc7224b --- /dev/null +++ b/lld/test/COFF/loadcfg-uninitialized.test @@ -0,0 +1,33 @@ +# RUN: yaml2obj %s -o %t.obj +# RUN: not lld-link -out:%t.dll %t.obj -dll -noentry 2>&1 | FileCheck %s +# CHECK: lld-link: error: _load_config_used points to uninitialized data + +--- !COFF +header: + Machine: IMAGE_FILE_MACHINE_AMD64 + Characteristics: [] +sections: + - Name: .rdata + Characteristics: [ IMAGE_SCN_CNT_UNINITIALIZED_DATA, IMAGE_SCN_MEM_READ ] + Alignment: 16 + VirtualSize: 0x140 +symbols: + - Name: .rdata + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 112 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 3 + - Name: _load_config_used + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL +... diff --git a/lld/test/COFF/reloc-discarded.s b/lld/test/COFF/reloc-discarded.s index 378804b62312..667df0faeb5a 100644 --- a/lld/test/COFF/reloc-discarded.s +++ b/lld/test/COFF/reloc-discarded.s @@ -8,10 +8,15 @@ # RUN: not lld-link -entry:main -nodefaultlib %t1.obj %t2.obj -out:%t.exe -opt:ref 2>&1 | FileCheck %s # RUN: not lld-link -entry:main -nodefaultlib %t1.obj %t2.obj -out:%t.exe -opt:noref 2>&1 | FileCheck %s +# RUN: not lld-link -entry:main -nodefaultlib %t1.obj %t2.obj -out:%t.exe -demangle:no 2>&1 \ +# RUN: | FileCheck --check-prefix=NODEMANGLE %s -# CHECK: error: relocation against symbol in discarded section: assoc_global +# CHECK: error: relocation against symbol in discarded section: int __cdecl assoc_global(void) # CHECK: >>> referenced by {{.*}}reloc-discarded{{.*}}.obj:(main) +# NODEMANGLE: error: relocation against symbol in discarded section: ?assoc_global@@YAHXZ +# NODEMANGLE: >>> referenced by {{.*}}reloc-discarded{{.*}}.obj:(main) + .section .bss,"bw",discard,main_global .globl main_global .p2align 2 @@ -20,12 +25,12 @@ main_global: .section .CRT$XCU,"dr",associative,main_global .p2align 3 -assoc_global: +"?assoc_global@@YAHXZ": .quad main_global .text .globl main main: - movq assoc_global(%rip), %rax + movq "?assoc_global@@YAHXZ"(%rip), %rax movl (%rax), %eax retq diff --git a/lld/test/COFF/start-lib.ll b/lld/test/COFF/start-lib.ll index ac12db067ffa..a46147f21ccb 100644 --- a/lld/test/COFF/start-lib.ll +++ b/lld/test/COFF/start-lib.ll @@ -1,26 +1,31 @@ ; REQUIRES: x86 -; -; RUN: llc -filetype=obj %s -o %t.obj -; RUN: llc -filetype=obj %p/Inputs/start-lib1.ll -o %t1.obj -; RUN: llc -filetype=obj %p/Inputs/start-lib2.ll -o %t2.obj -; RUN: opt -thinlto-bc %s -o %t.bc -; RUN: opt -thinlto-bc %p/Inputs/start-lib1.ll -o %t1.bc -; RUN: opt -thinlto-bc %p/Inputs/start-lib2.ll -o %t2.bc + +; RUN: rm -rf %t.dir +; RUN: split-file %s %t.dir + +; RUN: llc -filetype=obj %t.dir/main.ll -o %t.obj +; RUN: llc -filetype=obj %t.dir/start-lib1.ll -o %t1.obj +; RUN: llc -filetype=obj %t.dir/start-lib2.ll -o %t2.obj +; RUN: llc -filetype=obj %t.dir/eager.ll -o %t-eager.obj +; RUN: opt -thinlto-bc %t.dir/main.ll -o %t.bc +; RUN: opt -thinlto-bc %t.dir/start-lib1.ll -o %t1.bc +; RUN: opt -thinlto-bc %t.dir/start-lib2.ll -o %t2.bc +; RUN: opt -thinlto-bc %t.dir/eager.ll -o %t-eager.bc ; ; RUN: lld-link -out:%t1.exe -entry:main -opt:noref -lldmap:%t1.map \ -; RUN: %t.obj %t1.obj %t2.obj +; RUN: %t.obj %t1.obj %t2.obj %t-eager.obj ; RUN: FileCheck --check-prefix=TEST1 %s < %t1.map ; RUN: lld-link -out:%t1.exe -entry:main -opt:noref -lldmap:%t1.thinlto.map \ -; RUN: %t.bc %t1.bc %t2.bc +; RUN: %t.bc %t1.bc %t2.bc %t-eager.bc ; RUN: FileCheck --check-prefix=TEST1 %s < %t1.thinlto.map ; TEST1: foo ; TEST1: bar ; ; RUN: lld-link -out:%t2.exe -entry:main -opt:noref -lldmap:%t2.map \ -; RUN: %t.obj -start-lib %t1.obj -end-lib %t2.obj +; RUN: %t.obj -start-lib %t1.obj %t-eager.obj -end-lib %t2.obj ; RUN: FileCheck --check-prefix=TEST2 %s < %t2.map ; RUN: lld-link -out:%t2.exe -entry:main -opt:noref -lldmap:%t2.thinlto.map \ -; RUN: %t.bc -start-lib %t1.bc -end-lib %t2.bc +; RUN: %t.bc -start-lib %t1.bc %t-eager.bc -end-lib %t2.bc ; RUN: FileCheck --check-prefix=TEST2 %s < %t2.thinlto.map ; TEST2: Address Size Align Out In Symbol ; TEST2-NOT: {{ }}foo{{$}} @@ -28,18 +33,143 @@ ; TEST2-NOT: {{ }}foo{{$}} ; ; RUN: lld-link -out:%t3.exe -entry:main -opt:noref -lldmap:%t3.map \ -; RUN: %t.obj -start-lib %t1.obj %t2.obj +; RUN: %t.obj -start-lib %t1.obj %t2.obj %t-eager.obj ; RUN: FileCheck --check-prefix=TEST3 %s < %t3.map ; RUN: lld-link -out:%t3.exe -entry:main -opt:noref -lldmap:%t3.thinlto.map \ -; RUN: %t.bc -start-lib %t1.bc %t2.bc +; RUN: %t.bc -start-lib %t1.bc %t2.bc %t-eager.bc ; RUN: FileCheck --check-prefix=TEST3 %s < %t3.thinlto.map ; TEST3: Address Size Align Out In Symbol ; TEST3-NOT: {{ }}foo{{$}} ; TEST3-NOT: {{ }}bar{{$}} + +#--- main.ll + target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-pc-windows-msvc" +declare void @eager() + define void @main() { + call void @eager() + ret void +} + + +#--- start-lib1.ll + +target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-pc-windows-msvc" + +declare i32 @bar() + +define i32 @foo() { + %1 = call i32 () @bar() + %2 = add i32 %1, 1 + ret i32 %2 +} + +!llvm.linker.options = !{!0} +!0 = !{!"/INCLUDE:foo"} + + +#--- start-lib2.ll + +target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-pc-windows-msvc" + +define i32 @bar() { + ret i32 1 +} + +!llvm.linker.options = !{!0} +!0 = !{!"/INCLUDE:bar"} + +#--- eager.ll + +target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-pc-windows-msvc" + +define void @eager() { + ret void +} + +define i32 @ogre() { + ret i32 1 +} + + +; Check that lazy object files trigger loads correctly. +; If the links succeed, that's enough, no additional tests needed. + +; RUN: llc -filetype=obj %t.dir/main2.ll -o %t-main2.obj +; RUN: llc -filetype=obj %t.dir/foo.ll -o %t-foo.obj +; RUN: llc -filetype=obj %t.dir/bar.ll -o %t-bar.obj +; RUN: llc -filetype=obj %t.dir/baz.ll -o %t-baz.obj +; RUN: opt -thinlto-bc %t.dir/main2.ll -o %t-main2.bc +; RUN: opt -thinlto-bc %t.dir/foo.ll -o %t-foo.bc +; RUN: opt -thinlto-bc %t.dir/bar.ll -o %t-bar.bc +; RUN: opt -thinlto-bc %t.dir/baz.ll -o %t-baz.bc + +; RUN: lld-link -out:%t2.exe -entry:main \ +; RUN: %t-main2.obj %t-foo.obj %t-bar.obj %t-baz.obj +; RUN: lld-link -out:%t2.exe -entry:main \ +; RUN: %t-main2.obj /start-lib %t-foo.obj %t-bar.obj %t-baz.obj /end-lib +; RUN: lld-link -out:%t2.exe -entry:main \ +; RUN: /start-lib %t-foo.obj %t-bar.obj %t-baz.obj /end-lib %t-main2.obj + +; RUN: lld-link -out:%t2.exe -entry:main \ +; RUN: %t-main2.bc %t-foo.bc %t-bar.bc %t-baz.bc +; RUN: lld-link -out:%t2.exe -entry:main \ +; RUN: %t-main2.bc /start-lib %t-foo.bc %t-bar.bc %t-baz.bc /end-lib +; RUN: lld-link -out:%t2.exe -entry:main \ +; RUN: /start-lib %t-foo.bc %t-bar.bc %t-baz.bc /end-lib %t-main2.bc + +#--- main2.ll + +target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-pc-windows-msvc" + +declare void @bar() + +define void @main() { + call void () @bar() + ret void +} + + +#--- foo.ll + +target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-pc-windows-msvc" + +define void @foo() { + ret void +} + + +#--- bar.ll + +target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-pc-windows-msvc" + +; One undefined symbol from the lazy obj file before it, +; one from the one after it. +declare void @foo() +declare void @baz() + +define void @bar() { + call void () @foo() + call void () @baz() + ret void +} + + +#--- baz.ll + +target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-pc-windows-msvc" + +define void @baz() { ret void } diff --git a/lld/test/COFF/thin-archive.s b/lld/test/COFF/thin-archive.s index a35eabed688c..55d71ea63567 100644 --- a/lld/test/COFF/thin-archive.s +++ b/lld/test/COFF/thin-archive.s @@ -5,7 +5,22 @@ # RUN: llvm-mc -filetype=obj -triple=x86_64-windows-msvc -o %t.lib.obj \ # RUN: %S/Inputs/mangled-symbol.s # RUN: lld-link /lib /out:%t.lib %t.lib.obj -# RUN: lld-link /lib /llvmlibthin /out:%t_thin.lib %t.lib.obj +# RUN: lld-link /lib /llvmlibindex:no /out:%t_noindex.lib %t.lib.obj +# RUN: lld-link /lib /llvmlibthin /llvmlibindex /out:%t_thin.lib %t.lib.obj +# RUN: lld-link /lib /llvmlibthin /llvmlibindex:no \ +# RUN: /out:%t_thin_noindex.lib %t.lib.obj + +# RUN: llvm-nm --print-armap %t.lib \ +# RUN: | FileCheck %s --check-prefix=SYMTAB +# RUN: llvm-nm --print-armap %t_noindex.lib \ +# RUN: | FileCheck %s --check-prefix=NO-SYMTAB +# RUN: llvm-nm --print-armap %t_thin.lib \ +# RUN: | FileCheck %s --check-prefix=SYMTAB +# RUN: llvm-nm --print-armap %t_thin_noindex.lib \ +# RUN: | FileCheck %s --check-prefix=NO-SYMTAB + +# SYMTAB: ?f@@YAHXZ in +# NO-SYMTAB-NOT: ?f@@YAHXZ in # RUN: lld-link /entry:main %t.main.obj %t.lib /out:%t.exe 2>&1 | \ # RUN: FileCheck --allow-empty %s diff --git a/lld/test/ELF/Inputs/eager.s b/lld/test/ELF/Inputs/eager.s new file mode 100644 index 000000000000..1c6b6852bc78 --- /dev/null +++ b/lld/test/ELF/Inputs/eager.s @@ -0,0 +1,7 @@ +.globl eager +eager: + retq + +.globl ogre +ogre: + retq diff --git a/lld/test/ELF/aarch64-got-relocations-pauth.s b/lld/test/ELF/aarch64-got-relocations-pauth.s new file mode 100644 index 000000000000..2d37123f1cca --- /dev/null +++ b/lld/test/ELF/aarch64-got-relocations-pauth.s @@ -0,0 +1,144 @@ +# REQUIRES: aarch64 + +# RUN: rm -rf %t && split-file %s %t && cd %t + +# RUN: llvm-mc -filetype=obj -triple=aarch64 %p/Inputs/shared.s -o a.o +# RUN: ld.lld -shared a.o -o a.so + +#--- ok.s +# RUN: llvm-mc -filetype=obj -triple=aarch64 ok.s -o ok.o + +# RUN: ld.lld ok.o a.so -pie -o ok1 +# RUN: llvm-readelf -r -S -x .got ok1 | FileCheck %s --check-prefix=OK1 + +# RUN: ld.lld ok.o a.o -pie -o ok2 +# RUN: llvm-readelf -r -S -x .got -s ok2 | FileCheck %s --check-prefix=OK2 + +# OK1: Offset Info Type Symbol's Value Symbol's Name + Addend +# OK1-NEXT: 0000000000020380 0000000100000412 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 bar + 0 +# OK1-NEXT: 0000000000020388 0000000200000412 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 zed + 0 + +## Symbol's values for bar and zed are equal since they contain no content (see Inputs/shared.s) +# OK2: Offset Info Type Symbol's Value Symbol's Name + Addend +# OK2-NEXT: 0000000000020320 0000000000000411 R_AARCH64_AUTH_RELATIVE 10260 +# OK2-NEXT: 0000000000020328 0000000000000411 R_AARCH64_AUTH_RELATIVE 10260 + +# OK1: Hex dump of section '.got': +# OK1-NEXT: 0x00020380 00000000 00000080 00000000 000000a0 +## ^^ +## 0b10000000 bit 63 address diversity = true, bits 61..60 key = IA +## ^^ +## 0b10100000 bit 63 address diversity = true, bits 61..60 key = DA + +# OK2: Symbol table '.symtab' contains {{.*}} entries: +# OK2: Num: Value Size Type Bind Vis Ndx Name +# OK2: 0000000000010260 0 FUNC GLOBAL DEFAULT 6 bar +# OK2: 0000000000010260 0 NOTYPE GLOBAL DEFAULT 6 zed + +# OK2: Hex dump of section '.got': +# OK2-NEXT: 0x00020320 00000000 00000080 00000000 000000a0 +## ^^ +## 0b10000000 bit 63 address diversity = true, bits 61..60 key = IA +## ^^ +## 0b10100000 bit 63 address diversity = true, bits 61..60 key = DA + +# RUN: llvm-objdump -d ok1 | FileCheck %s --check-prefix=OK1-ASM + +# OK1-ASM: <_start>: +# OK1-ASM-NEXT: adrp x0, 0x20000 +# OK1-ASM-NEXT: ldr x0, [x0, #0x380] +# OK1-ASM-NEXT: adrp x1, 0x20000 +# OK1-ASM-NEXT: add x1, x1, #0x380 +# OK1-ASM-NEXT: adrp x0, 0x20000 +# OK1-ASM-NEXT: ldr x0, [x0, #0x388] +# OK1-ASM-NEXT: adrp x1, 0x20000 +# OK1-ASM-NEXT: add x1, x1, #0x388 + +# RUN: llvm-objdump -d ok2 | FileCheck %s --check-prefix=OK2-ASM + +# OK2-ASM: <_start>: +# OK2-ASM-NEXT: adrp x0, 0x20000 +# OK2-ASM-NEXT: ldr x0, [x0, #0x320] +# OK2-ASM-NEXT: adrp x1, 0x20000 +# OK2-ASM-NEXT: add x1, x1, #0x320 +# OK2-ASM-NEXT: adrp x0, 0x20000 +# OK2-ASM-NEXT: ldr x0, [x0, #0x328] +# OK2-ASM-NEXT: adrp x1, 0x20000 +# OK2-ASM-NEXT: add x1, x1, #0x328 + +.globl _start +_start: + adrp x0, :got_auth:bar + ldr x0, [x0, :got_auth_lo12:bar] + adrp x1, :got_auth:bar + add x1, x1, :got_auth_lo12:bar + adrp x0, :got_auth:zed + ldr x0, [x0, :got_auth_lo12:zed] + adrp x1, :got_auth:zed + add x1, x1, :got_auth_lo12:zed + +#--- ok-tiny.s +# RUN: llvm-mc -filetype=obj -triple=aarch64 ok-tiny.s -o ok-tiny.o + +# RUN: ld.lld ok-tiny.o a.so -pie -o tiny1 +# RUN: llvm-readelf -r -S -x .got tiny1 | FileCheck %s --check-prefix=TINY1 + +# RUN: ld.lld ok-tiny.o a.o -pie -o tiny2 +# RUN: llvm-readelf -r -S -x .got -s tiny2 | FileCheck %s --check-prefix=TINY2 + +# TINY1: Offset Info Type Symbol's Value Symbol's Name + Addend +# TINY1-NEXT: 0000000000020368 0000000100000412 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 bar + 0 +# TINY1-NEXT: 0000000000020370 0000000200000412 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 zed + 0 + +## Symbol's values for bar and zed are equal since they contain no content (see Inputs/shared.s) +# TINY2: Offset Info Type Symbol's Value Symbol's Name + Addend +# TINY2-NEXT: 0000000000020308 0000000000000411 R_AARCH64_AUTH_RELATIVE 10248 +# TINY2-NEXT: 0000000000020310 0000000000000411 R_AARCH64_AUTH_RELATIVE 10248 + +# TINY1: Hex dump of section '.got': +# TINY1-NEXT: 0x00020368 00000000 00000080 00000000 000000a0 +## ^^ +## 0b10000000 bit 63 address diversity = true, bits 61..60 key = IA +## ^^ +## 0b10100000 bit 63 address diversity = true, bits 61..60 key = DA + +# TINY2: Symbol table '.symtab' contains {{.*}} entries: +# TINY2: Num: Value Size Type Bind Vis Ndx Name +# TINY2: 0000000000010248 0 FUNC GLOBAL DEFAULT 6 bar +# TINY2: 0000000000010248 0 NOTYPE GLOBAL DEFAULT 6 zed + +# TINY2: Hex dump of section '.got': +# TINY2-NEXT: 0x00020308 00000000 00000080 00000000 000000a0 +## ^^ +## 0b10000000 bit 63 address diversity = true, bits 61..60 key = IA +## ^^ +## 0b10100000 bit 63 address diversity = true, bits 61..60 key = DA + +# RUN: llvm-objdump -d tiny1 | FileCheck %s --check-prefix=TINY1-ASM + +# TINY1-ASM: <_start>: +# TINY1-ASM-NEXT: adr x0, 0x20368 +# TINY1-ASM-NEXT: ldr x1, 0x20370 + +# RUN: llvm-objdump -d tiny2 | FileCheck %s --check-prefix=TINY2-ASM + +# TINY2-ASM: <_start>: +# TINY2-ASM-NEXT: adr x0, 0x20308 +# TINY2-ASM-NEXT: ldr x1, 0x20310 + +.globl _start +_start: + adr x0, :got_auth:bar + ldr x1, :got_auth:zed + +#--- err.s +# RUN: llvm-mc -filetype=obj -triple=aarch64 err.s -o err.o +# RUN: not ld.lld err.o a.so -pie 2>&1 | FileCheck %s --check-prefix=ERR --implicit-check-not=error: +# ERR: error: both AUTH and non-AUTH GOT entries for 'bar' requested, but only one type of GOT entry per symbol is supported + +.globl _start +_start: + adrp x0, :got_auth:bar + ldr x0, [x0, :got_auth_lo12:bar] + adrp x0, :got:bar + ldr x0, [x0, :got_lo12:bar] diff --git a/lld/test/ELF/arm-thumb-thunk-v6m-noshort.s b/lld/test/ELF/arm-thumb-thunk-v6m-noshort.s new file mode 100644 index 000000000000..43d6fc27f55c --- /dev/null +++ b/lld/test/ELF/arm-thumb-thunk-v6m-noshort.s @@ -0,0 +1,57 @@ +// REQUIRES: arm +// RUN: rm -rf %t && split-file %s %t && cd %t +// RUN: llvm-mc -filetype=obj -arm-add-build-attributes -triple=armv6m-none-eabi asm -o v6m.o +// RUN: ld.lld --script=lds v6m.o -o v6m +// RUN: llvm-objdump --no-print-imm-hex --no-show-raw-insn -d v6m --triple=armv6m-none-eabi | FileCheck %s + +// RUN: llvm-mc -filetype=obj -arm-add-build-attributes -triple=armv8m.base-none-eabi asm -o v8m.o +// RUN: ld.lld --script=lds v8m.o -o v8m +// RUN: llvm-objdump --no-print-imm-hex --no-show-raw-insn -d v8m --triple=armv8m.base-none-eabi | FileCheck --check-prefix=CHECKV8BASE %s + +/// Test that short thunks are not generated for v6-m as this architecture +/// does not have the B.w instruction. + +//--- asm + .syntax unified + + .section .text_low, "ax", %progbits + .thumb + .type _start, %function + .balign 4 + .globl _start +_start: + bl far + .space 0x1000 - (. - _start) + +/// Thunks will be inserted here. They are in short thunk range for a B.w +/// instruction. Expect v6-M to use a long thunk as v6-M does not have B.w. +/// Expect v8-m.base to use a short thunk as despite not having Thumb 2 it +/// does have B.w. + +// CHECK-LABEL: <__Thumbv6MABSLongThunk_far>: +// CHECK-NEXT: 2000: push {r0, r1} +// CHECK-NEXT: ldr r0, [pc, #4] +// CHECK-NEXT: str r0, [sp, #4] +// CHECK-NEXT: pop {r0, pc} +// CHECK-NEXT: 01 20 00 01 .word 0x01002001 + +// CHECKV8BASE-LABEL: <__Thumbv7ABSLongThunk_far>: +// CHECKV8BASE-NEXT: 2000: b.w 0x1002000 <far> + + .section .text_high, "ax", %progbits + .globl far + .type far, %function + .balign 4 +far: + bx lr + +//--- lds + +PHDRS { + low PT_LOAD FLAGS(0x1 | 0x4); + high PT_LOAD FLAGS(0x1 | 0x4); +} +SECTIONS { + .text_low 0x1000 : { *(.text_low) } + .text_high 0x1002000 : { *(.text_high) } +} diff --git a/lld/test/ELF/export-dynamic-symbol.s b/lld/test/ELF/export-dynamic-symbol.s index 3a00f07a420c..66050555e0c3 100644 --- a/lld/test/ELF/export-dynamic-symbol.s +++ b/lld/test/ELF/export-dynamic-symbol.s @@ -10,15 +10,16 @@ # so that we have time to investigate the issue without losing postcommit CI. # UNSUPPORTED: system-windows -# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o +# RUN: rm -rf %t && split-file %s %t && cd %t +# RUN: llvm-mc -filetype=obj -triple=x86_64 a.s -o %t.o ## For an executable, --export-dynamic-symbol exports a symbol if it is non-local and defined. -# RUN: ld.lld -pie --export-dynamic-symbol foo --export-dynamic-symbol qux %t.o -o %t -# RUN: llvm-nm -D -p %t | FileCheck %s +# RUN: ld.lld -pie --export-dynamic-symbol foo --export-dynamic-symbol qux %t.o -o out +# RUN: llvm-nm -D -p out | FileCheck %s # RUN: echo '{ foo; };' > %t1.list # RUN: echo '{ foo; qux; };' > %t2.list -# RUN: ld.lld -pie --export-dynamic-symbol-list=%t2.list %t.o -o %t -# RUN: llvm-nm -D -p %t | FileCheck %s +# RUN: ld.lld -pie --export-dynamic-symbol-list=%t2.list %t.o -o out +# RUN: llvm-nm -D -p out | FileCheck %s ## --export-dynamic exports all non-local defined symbols. ## --export-dynamic-symbol is shadowed. @@ -53,6 +54,20 @@ # RUN: ld.lld -shared -Bsymbolic --export-dynamic-symbol-list %t1.list %t.o -o %t.preempt # RUN: llvm-objdump -d %t.preempt | FileCheck --check-prefix=PLT1 %s +## Hidden symbols cannot be exported by --export-dynamic-symbol family options. +# RUN: llvm-mc -filetype=obj -triple=x86_64 hidden.s -o hidden.o +# RUN: ld.lld -pie %t.o hidden.o --dynamic-list hidden.list -o out.hidden +# RUN: llvm-readelf -s out.hidden | FileCheck %s --check-prefix=HIDDEN + +# HIDDEN: '.dynsym' contains 2 entries: +# HIDDEN: NOTYPE GLOBAL DEFAULT [[#]] _end +# HIDDEN: '.symtab' contains 6 entries: +# HIDDEN: FUNC LOCAL HIDDEN [[#]] foo +# HIDDEN-NEXT: NOTYPE LOCAL HIDDEN [[#]] _DYNAMIC +# HIDDEN-NEXT: NOTYPE GLOBAL DEFAULT [[#]] _start +# HIDDEN-NEXT: FUNC GLOBAL DEFAULT [[#]] qux +# HIDDEN-NEXT: NOTYPE GLOBAL DEFAULT [[#]] _end + ## 'nomatch' does not match any symbol. Don't warn. # RUN: ld.lld --fatal-warnings -shared -Bsymbolic-functions --export-dynamic-symbol nomatch %t.o -o %t.nopreempt2 # RUN: llvm-objdump -d %t.nopreempt2 | FileCheck --check-prefix=NOPLT %s @@ -80,6 +95,7 @@ # NOPLT-NOT: <foo@plt> # NOPLT-NOT: <qux@plt> +#--- a.s .global _start, foo, qux .type foo, @function .type qux, @function @@ -88,3 +104,13 @@ _start: call qux foo: qux: + +#--- hidden.s +.hidden foo + +.data +.quad _DYNAMIC +.quad _end + +#--- hidden.list +{foo;_end;_DYNAMIC;}; diff --git a/lld/test/ELF/linkerscript/discard-section-dynsym.s b/lld/test/ELF/linkerscript/discard-section-dynsym.s index 7c7c9c29cee8..f5d483dca86e 100644 --- a/lld/test/ELF/linkerscript/discard-section-dynsym.s +++ b/lld/test/ELF/linkerscript/discard-section-dynsym.s @@ -1,24 +1,43 @@ # REQUIRES: aarch64 ## We allow discarding .dynsym, check we don't crash. -# RUN: llvm-mc -filetype=obj -triple=aarch64 %s -o %t.o +# RUN: rm -rf %t && split-file %s %t && cd %t +# RUN: llvm-mc -filetype=obj -triple=aarch64 a.s -o a.o +# RUN: llvm-mc -filetype=obj -triple=aarch64 c.s -o c.o +# RUN: ld.lld -shared --version-script=c.ver c.o -o c.so -# RUN: echo 'SECTIONS { /DISCARD/ : { *(.dynsym) } }' > %t.lds -# RUN: ld.lld -shared -T %t.lds %t.o -o %t.so -# RUN: llvm-readelf -r %t.so | FileCheck %s +# RUN: echo 'SECTIONS { /DISCARD/ : { *(.dynsym) } }' > 1.lds +# RUN: ld.lld -shared -T 1.lds a.o c.so -o out1.so +# RUN: llvm-readelf -Sr out1.so | FileCheck %s --check-prefixes=CHECK,CHECK1 -# RUN: echo 'SECTIONS { /DISCARD/ : { *(.dynsym .dynstr) } }' > %t.lds -# RUN: ld.lld -shared -T %t.lds %t.o -o %t.so -# RUN: llvm-readelf -r %t.so | FileCheck %s +# RUN: echo 'SECTIONS { /DISCARD/ : { *(.dynsym .dynstr) } }' > 2.lds +# RUN: ld.lld -shared -T 2.lds a.o c.so -o out2.so +# RUN: llvm-readelf -Sr out2.so | FileCheck %s --check-prefixes=CHECK,CHECK2 + +# CHECK: [Nr] Name Type Address Off Size ES Flg Lk Inf Al +# CHECK-NEXT: [ 0] NULL 0000000000000000 000000 000000 00 0 0 0 +# CHECK-NEXT: [ 1] .gnu.version VERSYM 0000000000000000 {{.*}} 000006 02 A 0 0 2 +# CHECK1-NEXT: [ 2] .gnu.version_r VERNEED 0000000000000008 {{.*}} 000020 00 A 5 1 4 +# CHECK2-NEXT: [ 2] .gnu.version_r VERNEED 0000000000000008 {{.*}} 000020 00 A 0 1 4 +# CHECK1: [ 5] .dynstr STRTAB # CHECK: contains 2 entries: # CHECK: R_AARCH64_RELATIVE [[#]] # CHECK-NEXT: R_AARCH64_GLOB_DAT 0{{$}} +#--- a.s adrp x9, :got:var ldr x9, [x9, :got_lo12:var] + bl __libc_start_main .data .align 8 foo: .quad foo + +#--- c.s +.globl __libc_start_main +__libc_start_main: + +#--- c.ver +GLIBC_2.34 { __libc_start_main; }; diff --git a/lld/test/ELF/linkerscript/section-class.test b/lld/test/ELF/linkerscript/section-class.test index 7fce13bfe3e0..5c30b6343653 100644 --- a/lld/test/ELF/linkerscript/section-class.test +++ b/lld/test/ELF/linkerscript/section-class.test @@ -310,6 +310,7 @@ SECTIONS { .byte 0x12, 0x34 .section .b,"aM",@progbits,1 +.p2align 3 .byte 0x12 # RUN: llvm-mc -n -filetype=obj -triple=x86_64 merge.s -o merge.o @@ -317,10 +318,11 @@ SECTIONS { #--- spill-merge.lds ## SHF_MERGE sections are spilled according to the class refs of the first ## merged input section (the one giving the resulting section its name). +## Spills take into account increases in section alignment due to merging. MEMORY { a : ORIGIN = 0, LENGTH = 1 - b : ORIGIN = 1, LENGTH = 2 - c : ORIGIN = 3, LENGTH = 2 + b : ORIGIN = 1, LENGTH = 16 + c : ORIGIN = 17, LENGTH = 16 } SECTIONS { @@ -332,12 +334,14 @@ SECTIONS { } # RUN: ld.lld -T spill-merge.lds merge.o -o spill-merge -# RUN: llvm-readelf -S spill-merge | FileCheck %s --check-prefix=SPILL-MERGE +# RUN: llvm-readelf -S -x .second spill-merge | FileCheck %s --check-prefix=SPILL-MERGE -# SPILL-MERGE: Name Type Address Off Size +# SPILL-MERGE: Name Type Address Off Size # SPILL-MERGE: .first PROGBITS 0000000000000000 000190 000000 -# SPILL-MERGE-NEXT: .second PROGBITS 0000000000000001 001001 000002 -# SPILL-MERGE-NEXT: .third PROGBITS 0000000000000003 001003 000000 +# SPILL-MERGE-NEXT: .second PROGBITS 0000000000000008 001008 000009 +# SPILL-MERGE-NEXT: .third PROGBITS 0000000000000018 001018 000000 +# SPILL-MERGE: Hex dump of section '.second': +# SPILL-MERGE-NEXT: 0x00000008 12000000 00000000 34 . #--- link-order.s .section .a,"a",@progbits diff --git a/lld/test/ELF/lto/Inputs/eager.ll b/lld/test/ELF/lto/Inputs/eager.ll new file mode 100644 index 000000000000..ffd550e6f9cd --- /dev/null +++ b/lld/test/ELF/lto/Inputs/eager.ll @@ -0,0 +1,10 @@ +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +define void @eager() { + ret void +} + +define void @ogre() { + ret void +} diff --git a/lld/test/ELF/lto/Inputs/internalize-exportdyn.ll b/lld/test/ELF/lto/Inputs/internalize-exportdyn.ll index 585b99ae5a51..5bfe15c92b3f 100644 --- a/lld/test/ELF/lto/Inputs/internalize-exportdyn.ll +++ b/lld/test/ELF/lto/Inputs/internalize-exportdyn.ll @@ -1,6 +1,31 @@ target triple = "x86_64-unknown-linux-gnu" target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" +$ext_and_ext = comdat any +$lo_and_ext = comdat any +$lo_and_wo = comdat any +$wo_and_lo = comdat any + +declare void @foo(i64) + define weak_odr void @bah() { ret void } + +define void @ext_and_ext() local_unnamed_addr comdat { + call void @foo(i64 2) + ret void +} + +define linkonce_odr void @lo_and_ext() local_unnamed_addr comdat { + call void @foo(i64 2) + ret void +} + +define weak_odr void @lo_and_wo() local_unnamed_addr comdat { + ret void +} + +define linkonce_odr void @wo_and_lo() local_unnamed_addr comdat { + ret void +} diff --git a/lld/test/ELF/lto/internalize-exportdyn.ll b/lld/test/ELF/lto/internalize-exportdyn.ll index f02d3b375dad..25e319269bbd 100644 --- a/lld/test/ELF/lto/internalize-exportdyn.ll +++ b/lld/test/ELF/lto/internalize-exportdyn.ll @@ -1,14 +1,22 @@ ; REQUIRES: x86 -; RUN: llvm-as %s -o %t.o -; RUN: llvm-as %p/Inputs/internalize-exportdyn.ll -o %t2.o -; RUN: ld.lld %t.o %t2.o -o %t2 --export-dynamic -save-temps -; RUN: llvm-dis < %t2.0.2.internalize.bc | FileCheck %s -; RUN: ld.lld %t.o %t2.o -o %t3 -shared -save-temps -; RUN: llvm-dis < %t3.0.2.internalize.bc | FileCheck %s --check-prefix=DSO +; RUN: rm -rf %t && split-file %s %t && cd %t +; RUN: llvm-as a.ll -o a.bc +; RUN: llvm-as %p/Inputs/internalize-exportdyn.ll -o b.bc +; RUN: llvm-mc -filetype=obj -triple=x86_64 lib.s -o lib.o +; RUN: ld.lld a.bc b.bc lib.o -o out --export-dynamic -save-temps +; RUN: llvm-dis < out.0.2.internalize.bc | FileCheck %s +; RUN: ld.lld a.bc b.bc lib.o -o out2 -shared -save-temps +; RUN: llvm-dis < out2.0.2.internalize.bc | FileCheck %s --check-prefix=DSO +;--- a.ll target triple = "x86_64-unknown-linux-gnu" target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" +$ext_and_ext = comdat any +$lo_and_ext = comdat any +$lo_and_wo = comdat any +$wo_and_lo = comdat any + @c = linkonce_odr constant i32 1 @g = linkonce_odr global i32 1 @u_c = linkonce_odr unnamed_addr constant i32 1 @@ -16,6 +24,8 @@ target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16 @lu_c = linkonce_odr local_unnamed_addr constant i32 1 @lu_g = linkonce_odr local_unnamed_addr global i32 1 +declare void @lib(i64) + define void @_start() { ret void } @@ -46,6 +56,27 @@ define linkonce_odr void @baz() { @use_baz = global ptr @baz +;; Test comdat symbols that are prevailing in this module and non-prevailing in the other module. +define void @ext_and_ext() local_unnamed_addr comdat { + call void @foo(i64 1) + ret void +} + +;; linkonce_odr in this module and external in the other module. +define linkonce_odr void @lo_and_ext() local_unnamed_addr comdat { + call void @foo(i64 1) + ret void +} + +;; linkonce_odr in this module and weak_odr in the other module. +define linkonce_odr void @lo_and_wo() local_unnamed_addr comdat { + ret void +} + +define weak_odr void @wo_and_lo() local_unnamed_addr comdat { + ret void +} + ; Check what gets internalized. ; CHECK: @c = weak_odr dso_local constant i32 1 ; CHECK: @g = weak_odr dso_local global i32 1 @@ -60,6 +91,12 @@ define linkonce_odr void @baz() { ; CHECK: define internal void @zed2() ; CHECK: define weak_odr dso_local void @bah() ; CHECK: define weak_odr dso_local void @baz() +; CHECK: define dso_local void @ext_and_ext() comdat +; CHECK-NEXT: call void @foo(i64 1) +; CHECK: define internal void @lo_and_ext() comdat +; CHECK-NEXT: call void @foo(i64 1) +; CHECK: define weak_odr dso_local void @lo_and_wo() comdat +; CHECK: define weak_odr dso_local void @wo_and_lo() comdat ; DSO: @c = weak_odr constant i32 1 ; DSO: @g = weak_odr global i32 1 @@ -74,3 +111,11 @@ define linkonce_odr void @baz() { ; DSO: define internal void @zed2() ; DSO: define weak_odr void @bah() ; DSO: define weak_odr void @baz() +; DSO: define void @ext_and_ext() comdat +; DSO: define internal void @lo_and_ext() comdat +; DSO: define weak_odr void @lo_and_wo() comdat +; DSO: define weak_odr void @wo_and_lo() comdat + +;--- lib.s +.globl lib +lib: diff --git a/lld/test/ELF/lto/start-lib.ll b/lld/test/ELF/lto/start-lib.ll index 39f62a7b1074..6d508c6478ec 100644 --- a/lld/test/ELF/lto/start-lib.ll +++ b/lld/test/ELF/lto/start-lib.ll @@ -3,18 +3,19 @@ ; RUN: llvm-as %s -o %t1.o ; RUN: llvm-as %p/Inputs/start-lib1.ll -o %t2.o ; RUN: llvm-as %p/Inputs/start-lib2.ll -o %t3.o +; RUN: llvm-as %p/Inputs/eager.ll -o %t-eager.o ; -; RUN: ld.lld -shared -o %t3 %t1.o %t2.o %t3.o +; RUN: ld.lld -shared -o %t3 %t1.o %t2.o %t3.o %t-eager.o ; RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=TEST1 %s ; TEST1: Name: foo ; TEST1: Name: bar ; -; RUN: ld.lld -shared -o %t3 -u bar %t1.o --start-lib %t2.o %t3.o +; RUN: ld.lld -shared -o %t3 -u bar %t1.o --start-lib %t2.o %t3.o %t-eager.o ; RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=TEST2 %s ; TEST2-NOT: Name: foo ; TEST2: Name: bar ; -; RUN: ld.lld -shared -o %t3 %t1.o --start-lib %t2.o %t3.o +; RUN: ld.lld -shared -o %t3 %t1.o --start-lib %t2.o %t3.o %t-eager.o ; RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=TEST3 %s ; TEST3-NOT: Name: foo ; TEST3-NOT: Name: bar @@ -22,6 +23,9 @@ target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu" +declare void @eager() + define void @_start() { + call void @eager() ret void } diff --git a/lld/test/ELF/openbsd-phdr.s b/lld/test/ELF/openbsd-phdr.s index 275f94451170..e0269e642f75 100644 --- a/lld/test/ELF/openbsd-phdr.s +++ b/lld/test/ELF/openbsd-phdr.s @@ -4,8 +4,11 @@ # RUN: ld.lld randomdata.o -o randomdata # RUN: llvm-readelf -S -l randomdata | FileCheck %s --check-prefix=RANDOMDATA -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-openbsd /dev/null -o wxneeded.o -# RUN: ld.lld -z wxneeded wxneeded.o -o wxneeded +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-openbsd /dev/null -o empty.o +# RUN: ld.lld -z nobtcfi empty.o -o nobtcfi +# RUN: llvm-readelf -l nobtcfi | FileCheck %s --check-prefix=NOBTCFI + +# RUN: ld.lld -z wxneeded empty.o -o wxneeded # RUN: llvm-readelf -l wxneeded | FileCheck %s --check-prefix=WXNEEDED # RUN: ld.lld -T lds randomdata.o -o out @@ -14,6 +17,9 @@ # RANDOMDATA: Name Type Address Off Size ES Flg Lk Inf Al # RANDOMDATA: .openbsd.randomdata PROGBITS [[ADDR:[0-9a-f]+]] [[O:[0-9a-f]+]] 000008 00 A 0 0 1 +# NOBTCFI: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align +# NOBTCFI: OPENBSD_NOBTCFI 0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 E 0 + # WXNEEDED: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align # WXNEEDED: OPENBSD_WXNEEDED 0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 E 0 diff --git a/lld/test/ELF/randomize-section-padding.test b/lld/test/ELF/randomize-section-padding.test new file mode 100644 index 000000000000..af8e4f14981c --- /dev/null +++ b/lld/test/ELF/randomize-section-padding.test @@ -0,0 +1,125 @@ +# REQUIRES: x86 +# RUN: split-file %s %t +# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/a.s -o %t/a.o + +## --randomize-section-padding= inserts segment offset padding and pre-section +## padding, and does not affect flags. Segment offset padding is only inserted +## when PT_LOAD changes, as shown by .bss size (.data and .bss share a PT_LOAD). + +# RUN: ld.lld --randomize-section-padding=6 %t/a.o -o %t/a.out +# RUN: llvm-readelf -sS -x .rodata -x .text -x .data %t/a.out | FileCheck --check-prefix=PAD6 %s + +# PAD6: .rodata PROGBITS 0000000000200158 000158 000b8d 00 A 0 0 1 +# PAD6-NEXT: .text PROGBITS 0000000000201ce8 000ce8 000270 00 AX 0 0 4 +# PAD6-NEXT: .data PROGBITS 0000000000202f58 000f58 000941 00 WA 0 0 1 +# PAD6-NEXT: .bss NOBITS 0000000000203899 001899 000003 00 WA 0 0 1 + +# PAD6: 0000000000203899 0 NOTYPE LOCAL DEFAULT 4 a +# PAD6: 000000000020389a 0 NOTYPE LOCAL DEFAULT 4 b +# PAD6: 000000000020389b 0 NOTYPE LOCAL DEFAULT 4 c + +# PAD6: Hex dump of section '.rodata': +# PAD6: 0x00200cd8 00000000 00000000 00000102 03 +# PAD6: Hex dump of section '.text': +# PAD6: 0x00201f48 cccccccc cccccccc cccccccc 0405cc06 +# PAD6: Hex dump of section '.data': +# PAD6: 0x00203888 00000000 00000000 00000000 00000708 +# PAD6: 0x00203898 09 + +## Size of segment offset padding and location of pre-section padding is +## dependent on the seed. + +# RUN: ld.lld --randomize-section-padding=46 %t/a.o -o %t/a.out +# RUN: llvm-readelf -sS -x .rodata -x .text -x .data %t/a.out | FileCheck --check-prefix=PAD46 %s + +# PAD46: .rodata PROGBITS 0000000000200158 000158 000cc0 00 A 0 0 1 +# PAD46-NEXT: .text PROGBITS 0000000000201e18 000e18 0009bf 00 AX 0 0 4 +# PAD46-NEXT: .data PROGBITS 00000000002037d7 0017d7 000540 00 WA 0 0 1 +# PAD46-NEXT: .bss NOBITS 0000000000203d17 001d17 000004 00 WA 0 0 1 + +# PAD46: 0000000000203d17 0 NOTYPE LOCAL DEFAULT 4 a +# PAD46: 0000000000203d18 0 NOTYPE LOCAL DEFAULT 4 b +# PAD46: 0000000000203d1a 0 NOTYPE LOCAL DEFAULT 4 c + +# PAD46: Hex dump of section '.rodata': +# PAD46: 0x00200e08 00000000 00000000 00000000 00010203 +# PAD46: Hex dump of section '.text': +# PAD46: 0x002027c8 cccccccc cccccccc cccccccc 040506 +# PAD46: Hex dump of section '.data': +# PAD46: 0x00203d07 00000000 00000000 00000000 07000809 + +## When there are multiple InputSectionDescriptions for an output section, +## segment offset padding is inserted in the first InputSectionDescription. + +# RUN: ld.lld --randomize-section-padding=46 %t/a.o %t/a.lds -o %t/a.out + +# RUN: llvm-readelf -sS -x .rodata -x .text -x .data %t/a.out | FileCheck --check-prefix=PAD46-LDS %s + +# PAD46-LDS: .rodata PROGBITS 0000000000000158 000158 000cc0 00 A 0 0 1 +# PAD46-LDS-NEXT: .text PROGBITS 0000000000001000 001000 0009c0 00 AX 0 0 4 +# PAD46-LDS-NEXT: .data PROGBITS 0000000000002000 002000 000540 00 WA 0 0 1 +# PAD46-LDS-NEXT: .bss NOBITS 0000000000002540 002540 000004 00 WA 0 0 1 + +# PAD46-LDS: 0000000000002543 0 NOTYPE LOCAL DEFAULT 4 a +# PAD46-LDS: 0000000000002541 0 NOTYPE LOCAL DEFAULT 4 b +# PAD46-LDS: 0000000000002540 0 NOTYPE LOCAL DEFAULT 4 c + +# PAD46-LDS: Hex dump of section '.rodata': +# PAD46-LDS: 0x00000e08 00000000 00000000 00000000 00030201 ................ +# PAD46-LDS: Hex dump of section '.text': +# PAD46-LDS: 0x000019b0 cccccccc cccccccc cccc0605 04cccccc ................ +# PAD46-LDS: Hex dump of section '.data': +# PAD46-LDS: 0x00002530 00000000 00000000 00000000 09000807 ................ + +#--- a.s + +.section .rodata.a,"a",@progbits +.byte 1 + +.section .rodata.b,"a",@progbits +.byte 2 + +.section .rodata.c,"a",@progbits +.byte 3 + +.section .text.a,"ax",@progbits +.byte 4 + +.section .text.b,"ax",@progbits +.byte 5 + +.section .text.c,"ax",@progbits +.byte 6 + +.section .data.a,"aw",@progbits +.byte 7 + +.section .data.b,"aw",@progbits +.byte 8 + +.section .data.c,"aw",@progbits +.byte 9 + +.section .bss.a,"a",@nobits +a: +.zero 1 + +.section .bss.b,"a",@nobits +b: +.zero 1 + +.section .bss.c,"a",@nobits +c: +.zero 1 + +#--- a.lds + +SECTIONS { + . = SIZEOF_HEADERS; + .rodata : { *(.rodata.c) *(.rodata.b) *(.rodata.a) } + . = ALIGN(CONSTANT(MAXPAGESIZE)); + .text : { *(.text.c) *(.text.b) *(.text.a) } + . = ALIGN(CONSTANT(MAXPAGESIZE)); + .data : { *(.data.c) *(.data.b) *(.data.a) } + .bss : { *(.bss.c) *(.bss.b) *(.bss.a) } +} diff --git a/lld/test/ELF/start-lib.s b/lld/test/ELF/start-lib.s index 04ac5a6323d0..5bd0bd628bf3 100644 --- a/lld/test/ELF/start-lib.s +++ b/lld/test/ELF/start-lib.s @@ -5,18 +5,20 @@ // RUN: %p/Inputs/start-lib1.s -o %t2.o // RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux \ // RUN: %p/Inputs/start-lib2.s -o %t3.o +// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux \ +// RUN: %p/Inputs/eager.s -o %t-eager.o -// RUN: ld.lld -o %t3 %t1.o %t2.o %t3.o +// RUN: ld.lld -o %t3 %t1.o %t2.o %t3.o %t-eager.o // RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=TEST1 %s // TEST1: Name: foo // TEST1: Name: bar -// RUN: ld.lld -o %t3 %t1.o -u bar --start-lib %t2.o %t3.o +// RUN: ld.lld -o %t3 %t1.o -u bar --start-lib %t2.o %t3.o %t-eager.o // RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=TEST2 %s // TEST2-NOT: Name: foo // TEST2: Name: bar -// RUN: ld.lld -o %t3 %t1.o --start-lib %t2.o %t3.o +// RUN: ld.lld -o %t3 %t1.o --start-lib %t2.o %t3.o %t-eager.o // RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=TEST3 %s // TEST3-NOT: Name: foo // TEST3-NOT: Name: bar @@ -32,3 +34,4 @@ .globl _start _start: + callq eager diff --git a/lld/test/ELF/tls-opt.s b/lld/test/ELF/tls-opt.s index 08cc52afd641..466dda0ef2e7 100644 --- a/lld/test/ELF/tls-opt.s +++ b/lld/test/ELF/tls-opt.s @@ -28,17 +28,17 @@ // DISASM-NEXT: addq $-8, %r28 // DISASM-NEXT: addq $-4, %r16 # NDD -// DISASM-NEXT: addq $-10, %r16, %r16 -// DISASM-NEXT: addq $-10, %r16, %r20 -// DISASM-NEXT: addq $-10, %r16, %rax -// DISASM-NEXT: addq $-10, %rax, %r16 -// DISASM-NEXT: addq $-10, %r8, %r16 -// DISASM-NEXT: addq $-10, %rax, %r12 +// DISASM-NEXT: addq $-8, %r16, %r16 +// DISASM-NEXT: addq $-8, %r16, %r20 +// DISASM-NEXT: addq $-8, %r16, %rax +// DISASM-NEXT: addq $-8, %rax, %r16 +// DISASM-NEXT: addq $-8, %r8, %r16 +// DISASM-NEXT: addq $-8, %rax, %r12 # NDD + NF -// DISASM-NEXT: {nf} addq $-10, %r8, %r16 -// DISASM-NEXT: {nf} addq $-10, %rax, %r12 +// DISASM-NEXT: {nf} addq $-8, %r8, %r16 +// DISASM-NEXT: {nf} addq $-8, %rax, %r12 # NF -// DISASM-NEXT: {nf} addq $-10, %r12 +// DISASM-NEXT: {nf} addq $-8, %r12 // LD to LE: // DISASM-NEXT: movq %fs:0, %rax diff --git a/lld/test/ELF/x86-64-tls-ie-local.s b/lld/test/ELF/x86-64-tls-ie-local.s index 0a104e7d6727..704ecacc9619 100644 --- a/lld/test/ELF/x86-64-tls-ie-local.s +++ b/lld/test/ELF/x86-64-tls-ie-local.s @@ -17,21 +17,21 @@ ## &.got[1] - 0x1286 = 0x2380 - 0x1286 = 4346 ## &.got[2] - 0x128e = 0x2378 - 0x128e = 4330 ## &.got[3] - 0x1296 = 0x2380 - 0x1296 = 4330 -## &.got[0] - 0x12a0 = 0x2376 - 0x12a0 = 4310 -## &.got[1] - 0x12aa = 0x237e - 0x12aa = 4308 -## &.got[0] - 0x12b4 = 0x2376 - 0x12b4 = 4290 -## &.got[1] - 0x12be = 0x237e - 0x12be = 4288 -## &.got[0] - 0x12c8 = 0x2376 - 0x12c8 = 4270 +## &.got[0] - 0x12a0 = 0x2378 - 0x12a0 = 4312 +## &.got[1] - 0x12aa = 0x2380 - 0x12aa = 4310 +## &.got[0] - 0x12b4 = 0x2378 - 0x12b4 = 4292 +## &.got[1] - 0x12be = 0x2380 - 0x12be = 4290 +## &.got[0] - 0x12c8 = 0x2378 - 0x12c8 = 4272 # CHECK: 1278: addq 4345(%rip), %rax # CHECK-NEXT: 127f: addq 4346(%rip), %rax # CHECK-NEXT: 1286: addq 4330(%rip), %r16 # CHECK-NEXT: 128e: addq 4330(%rip), %r16 -# CHECK-NEXT: 1296: addq %r8, 4310(%rip), %r16 -# CHECK-NEXT: 12a0: addq 4308(%rip), %rax, %r12 -# CHECK-NEXT: 12aa: {nf} addq %r8, 4290(%rip), %r16 -# CHECK-NEXT: 12b4: {nf} addq 4288(%rip), %rax, %r12 -# CHECK-NEXT: 12be: {nf} addq 4270(%rip), %r12 +# CHECK-NEXT: 1296: addq %r8, 4312(%rip), %r16 +# CHECK-NEXT: 12a0: addq 4310(%rip), %rax, %r12 +# CHECK-NEXT: 12aa: {nf} addq %r8, 4292(%rip), %r16 +# CHECK-NEXT: 12b4: {nf} addq 4290(%rip), %rax, %r12 +# CHECK-NEXT: 12be: {nf} addq 4272(%rip), %r12 addq foo@GOTTPOFF(%rip), %rax addq bar@GOTTPOFF(%rip), %rax diff --git a/lld/test/MachO/bp-section-orderer-errs.s b/lld/test/MachO/bp-section-orderer-errs.s index 682eb0c08bf1..abeb25122a92 100644 --- a/lld/test/MachO/bp-section-orderer-errs.s +++ b/lld/test/MachO/bp-section-orderer-errs.s @@ -1,12 +1,22 @@ -# RUN: not %lld -o /dev/null --irpgo-profile-sort %s --call-graph-profile-sort 2>&1 | FileCheck %s --check-prefix=IRPGO-ERR -# RUN: not %lld -o /dev/null --irpgo-profile-sort=%s --call-graph-profile-sort 2>&1 | FileCheck %s --check-prefix=IRPGO-ERR +# RUN: not %no-fatal-warnings-lld -o /dev/null --irpgo-profile-sort %s --call-graph-profile-sort 2>&1 | FileCheck %s --check-prefix=IRPGO-ERR +# RUN: not %no-fatal-warnings-lld -o /dev/null --irpgo-profile-sort=%s --call-graph-profile-sort 2>&1 | FileCheck %s --check-prefix=IRPGO-ERR # IRPGO-ERR: --irpgo-profile-sort is incompatible with --call-graph-profile-sort # RUN: not %lld -o /dev/null --compression-sort=function --call-graph-profile-sort %s 2>&1 | FileCheck %s --check-prefix=COMPRESSION-ERR -# COMPRESSION-ERR: --compression-sort= is incompatible with --call-graph-profile-sort +# RUN: not %lld -o /dev/null --bp-compression-sort=function --call-graph-profile-sort %s 2>&1 | FileCheck %s --check-prefix=COMPRESSION-ERR +# COMPRESSION-ERR: --bp-compression-sort= is incompatible with --call-graph-profile-sort # RUN: not %lld -o /dev/null --compression-sort=malformed 2>&1 | FileCheck %s --check-prefix=COMPRESSION-MALFORM -# COMPRESSION-MALFORM: unknown value `malformed` for --compression-sort= +# RUN: not %lld -o /dev/null --bp-compression-sort=malformed 2>&1 | FileCheck %s --check-prefix=COMPRESSION-MALFORM +# COMPRESSION-MALFORM: unknown value `malformed` for --bp-compression-sort= # RUN: not %lld -o /dev/null --compression-sort-startup-functions 2>&1 | FileCheck %s --check-prefix=STARTUP -# STARTUP: --compression-sort-startup-functions must be used with --irpgo-profile-sort +# RUN: not %lld -o /dev/null --bp-compression-sort-startup-functions 2>&1 | FileCheck %s --check-prefix=STARTUP +# STARTUP: --bp-compression-sort-startup-functions must be used with --bp-startup-sort=function + +# RUN: not %lld -o /dev/null --irpgo-profile %s --bp-startup-sort=function --call-graph-profile-sort 2>&1 | FileCheck %s --check-prefix=IRPGO-STARTUP +# RUN: not %lld -o /dev/null --irpgo-profile=%s --bp-startup-sort=function --call-graph-profile-sort 2>&1 | FileCheck %s --check-prefix=IRPGO-STARTUP +# IRPGO-STARTUP: --bp-startup-sort= is incompatible with --call-graph-profile-sort + +# RUN: not %lld -o /dev/null --bp-startup-sort=function 2>&1 | FileCheck %s --check-prefix=STARTUP-COMPRESSION +# STARTUP-COMPRESSION: --bp-startup-sort=function must be used with --irpgo-profile diff --git a/lld/test/MachO/bp-section-orderer-stress.s b/lld/test/MachO/bp-section-orderer-stress.s index 986e2d8fd106..0bfd99eb3dd8 100644 --- a/lld/test/MachO/bp-section-orderer-stress.s +++ b/lld/test/MachO/bp-section-orderer-stress.s @@ -7,10 +7,13 @@ # RUN: llvm-mc -filetype=obj -triple=arm64-apple-darwin %t.s -o %t.o # RUN: llvm-profdata merge %t.proftext -o %t.profdata -# RUN: %lld -arch arm64 -lSystem -e _main --icf=all -o - %t.o --irpgo-profile-sort=%t.profdata --compression-sort-startup-functions --compression-sort=both | llvm-nm --numeric-sort --format=just-symbols - > %t.order1.txt -# RUN: %lld -arch arm64 -lSystem -e _main --icf=all -o - %t.o --irpgo-profile-sort=%t.profdata --compression-sort-startup-functions --compression-sort=both | llvm-nm --numeric-sort --format=just-symbols - > %t.order2.txt +# RUN: %no-fatal-warnings-lld -arch arm64 -lSystem -e _main --icf=all -o - %t.o --irpgo-profile-sort=%t.profdata --compression-sort-startup-functions --compression-sort=both | llvm-nm --numeric-sort --format=just-symbols - > %t.order1.txt +# RUN: %no-fatal-warnings-lld -arch arm64 -lSystem -e _main --icf=all -o - %t.o --irpgo-profile-sort=%t.profdata --compression-sort-startup-functions --compression-sort=both | llvm-nm --numeric-sort --format=just-symbols - > %t.order2.txt # RUN: diff %t.order1.txt %t.order2.txt +# RUN: %lld -arch arm64 -lSystem -e _main --icf=all -o - %t.o --irpgo-profile=%t.profdata --bp-startup-sort=function --bp-compression-sort-startup-functions --bp-compression-sort=both | llvm-nm --numeric-sort --format=just-symbols - > %t.order1.txt +# RUN: %lld -arch arm64 -lSystem -e _main --icf=all -o - %t.o --irpgo-profile=%t.profdata --bp-startup-sort=function --bp-compression-sort-startup-functions --bp-compression-sort=both | llvm-nm --numeric-sort --format=just-symbols - > %t.order2.txt +# RUN: diff %t.order1.txt %t.order2.txt import random import sys diff --git a/lld/test/MachO/bp-section-orderer.s b/lld/test/MachO/bp-section-orderer.s index 407787025150..2eaff04bdc04 100644 --- a/lld/test/MachO/bp-section-orderer.s +++ b/lld/test/MachO/bp-section-orderer.s @@ -4,13 +4,21 @@ # RUN: llvm-mc -filetype=obj -triple=arm64-apple-darwin %t/a.s -o %t/a.o # RUN: llvm-profdata merge %t/a.proftext -o %t/a.profdata -# RUN: %lld -arch arm64 -lSystem -e _main -o %t/a.out %t/a.o --irpgo-profile-sort=%t/a.profdata --verbose-bp-section-orderer 2>&1 | FileCheck %s --check-prefix=STARTUP -# RUN: %lld -arch arm64 -lSystem -e _main -o %t/a.out %t/a.o --irpgo-profile-sort=%t/a.profdata --verbose-bp-section-orderer --icf=all --compression-sort=none 2>&1 | FileCheck %s --check-prefix=STARTUP +# RUN: %no-fatal-warnings-lld -arch arm64 -lSystem -e _main -o %t/a.out %t/a.o --irpgo-profile-sort=%t/a.profdata --verbose-bp-section-orderer 2>&1 | FileCheck %s --check-prefix=STARTUP +# RUN: %no-fatal-warnings-lld -arch arm64 -lSystem -e _main -o %t/a.out %t/a.o --irpgo-profile-sort=%t/a.profdata --verbose-bp-section-orderer --icf=all --compression-sort=none 2>&1 | FileCheck %s --check-prefix=STARTUP +# RUN: %lld -arch arm64 -lSystem -e _main -o %t/a.out %t/a.o --irpgo-profile %t/a.profdata --bp-startup-sort=function --verbose-bp-section-orderer 2>&1 | FileCheck %s --check-prefix=STARTUP +# RUN: %lld -arch arm64 -lSystem -e _main -o %t/a.out %t/a.o --irpgo-profile=%t/a.profdata --bp-startup-sort=function --verbose-bp-section-orderer --icf=all --bp-compression-sort=none 2>&1 | FileCheck %s --check-prefix=STARTUP # STARTUP: Ordered 3 sections using balanced partitioning -# RUN: %lld -arch arm64 -lSystem -e _main -o - %t/a.o --irpgo-profile-sort=%t/a.profdata -order_file %t/a.orderfile | llvm-nm --numeric-sort --format=just-symbols - | FileCheck %s --check-prefix=ORDERFILE +# Check that orderfiles take precedence over BP +# RUN: %no-fatal-warnings-lld -arch arm64 -lSystem -e _main -o - %t/a.o -order_file %t/a.orderfile --irpgo-profile-sort=%t/a.profdata | llvm-nm --numeric-sort --format=just-symbols - | FileCheck %s --check-prefix=ORDERFILE +# RUN: %lld -arch arm64 -lSystem -e _main -o - %t/a.o -order_file %t/a.orderfile --compression-sort=both | llvm-nm --numeric-sort --format=just-symbols - | FileCheck %s --check-prefix=ORDERFILE +# RUN: %lld -arch arm64 -lSystem -e _main -o - %t/a.o -order_file %t/a.orderfile --irpgo-profile=%t/a.profdata --bp-startup-sort=function | llvm-nm --numeric-sort --format=just-symbols - | FileCheck %s --check-prefix=ORDERFILE +# RUN: %lld -arch arm64 -lSystem -e _main -o - %t/a.o -order_file %t/a.orderfile --bp-compression-sort=both | llvm-nm --numeric-sort --format=just-symbols - | FileCheck %s --check-prefix=ORDERFILE + +# Functions # ORDERFILE: A # ORDERFILE: F # ORDERFILE: E @@ -18,19 +26,29 @@ # ORDERFILE-DAG: _main # ORDERFILE-DAG: _B # ORDERFILE-DAG: l_C + +# Data +# ORDERFILE: s3 +# ORDERFILE: r3 +# ORDERFILE: r2 # ORDERFILE-DAG: s1 # ORDERFILE-DAG: s2 # ORDERFILE-DAG: r1 -# ORDERFILE-DAG: r2 +# ORDERFILE-DAG: r4 # RUN: %lld -arch arm64 -lSystem -e _main -o %t/a.out %t/a.o --verbose-bp-section-orderer --compression-sort=function 2>&1 | FileCheck %s --check-prefix=COMPRESSION-FUNC # RUN: %lld -arch arm64 -lSystem -e _main -o %t/a.out %t/a.o --verbose-bp-section-orderer --compression-sort=data 2>&1 | FileCheck %s --check-prefix=COMPRESSION-DATA # RUN: %lld -arch arm64 -lSystem -e _main -o %t/a.out %t/a.o --verbose-bp-section-orderer --compression-sort=both 2>&1 | FileCheck %s --check-prefix=COMPRESSION-BOTH -# RUN: %lld -arch arm64 -lSystem -e _main -o %t/a.out %t/a.o --verbose-bp-section-orderer --compression-sort=both --irpgo-profile-sort=%t/a.profdata 2>&1 | FileCheck %s --check-prefix=COMPRESSION-BOTH +# RUN: %no-fatal-warnings-lld -arch arm64 -lSystem -e _main -o %t/a.out %t/a.o --verbose-bp-section-orderer --compression-sort=both --irpgo-profile-sort=%t/a.profdata 2>&1 | FileCheck %s --check-prefix=COMPRESSION-BOTH + +# RUN: %lld -arch arm64 -lSystem -e _main -o %t/a.out %t/a.o --verbose-bp-section-orderer --bp-compression-sort=function 2>&1 | FileCheck %s --check-prefix=COMPRESSION-FUNC +# RUN: %lld -arch arm64 -lSystem -e _main -o %t/a.out %t/a.o --verbose-bp-section-orderer --bp-compression-sort=data 2>&1 | FileCheck %s --check-prefix=COMPRESSION-DATA +# RUN: %lld -arch arm64 -lSystem -e _main -o %t/a.out %t/a.o --verbose-bp-section-orderer --bp-compression-sort=both 2>&1 | FileCheck %s --check-prefix=COMPRESSION-BOTH +# RUN: %lld -arch arm64 -lSystem -e _main -o %t/a.out %t/a.o --verbose-bp-section-orderer --bp-compression-sort=both --irpgo-profile=%t/a.profdata --bp-startup-sort=function 2>&1 | FileCheck %s --check-prefix=COMPRESSION-BOTH # COMPRESSION-FUNC: Ordered 7 sections using balanced partitioning -# COMPRESSION-DATA: Ordered 4 sections using balanced partitioning -# COMPRESSION-BOTH: Ordered 11 sections using balanced partitioning +# COMPRESSION-DATA: Ordered 7 sections using balanced partitioning +# COMPRESSION-BOTH: Ordered 14 sections using balanced partitioning #--- a.s .text @@ -66,10 +84,16 @@ s1: .ascii "hello world" s2: .ascii "i am a string" +s3: + .ascii "this is s3" r1: .quad s1 r2: .quad r1 +r3: + .quad r2 +r4: + .quad s2 .subsections_via_symbols @@ -121,3 +145,6 @@ A F E D +s3 +r3 +r2 diff --git a/lld/test/MinGW/driver.test b/lld/test/MinGW/driver.test index ed6bc880f8f2..907d2d87dda5 100644 --- a/lld/test/MinGW/driver.test +++ b/lld/test/MinGW/driver.test @@ -462,3 +462,6 @@ RUN: ld.lld -### foo.o -m i386pep --rpath foo 2>&1 | FileCheck -check-prefix=WAR RUN: ld.lld -### foo.o -m i386pep -rpath=foo 2>&1 | FileCheck -check-prefix=WARN_RPATH %s RUN: ld.lld -### foo.o -m i386pep --rpath=foo 2>&1 | FileCheck -check-prefix=WARN_RPATH %s WARN_RPATH: warning: parameter -{{-?}}rpath has no effect on PE/COFF targets + +RUN: ld.lld -### foo.o -m i386pe --dependent-load-flag=0x800 2>&1 | FileCheck -check-prefix=DEPENDENT_LOAD_FLAG %s +DEPENDENT_LOAD_FLAG: -dependentloadflag:0x800 diff --git a/lld/test/wasm/dylink-non-pie.s b/lld/test/wasm/dylink-non-pie.s new file mode 100755 index 000000000000..3157b8c32120 --- /dev/null +++ b/lld/test/wasm/dylink-non-pie.s @@ -0,0 +1,38 @@ +# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.lib.o %p/Inputs/ret32.s +# RUN: wasm-ld -m wasm32 --experimental-pic -shared --no-entry %t.lib.o -o %t.lib.so +# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.o %s +# RUN: wasm-ld -m wasm32 -Bdynamic %t.o %t.lib.so -o %t.wasm +# RUN: obj2yaml %t.wasm | FileCheck %s +# RUN: llvm-objdump -d --no-show-raw-insn --no-leading-addr %t.wasm | FileCheck %s --check-prefixes DIS + + .functype ret32 (f32) -> (i32) + .globl _start +_start: + .functype _start () -> () + i32.const f_p + drop + end_function + + .section .data.f_p,"",@ +f_p: + .int32 ret32 + .size f_p, 4 + +# CHECK: Sections: +# CHECK-NEXT: - Type: CUSTOM +# CHECK-NEXT: Name: dylink.0 + +# non-pie executable doesn't import __memory_base +# CHECK: - Type: IMPORT +# CHECK-NOT: Field: __memory_base + +# CHECK: - Type: EXPORT +# CHECK: - Name: __wasm_apply_data_relocs +# CHECK-NEXT: Kind: FUNCTION + +# DIS: <__wasm_apply_data_relocs>: +# DIS-EMPTY: +# DIS-NEXT: i32.const 1024 +# DIS-NEXT: global.get 0 +# DIS-NEXT: i32.store 0 +# DIS-NEXT: end |
