diff --git a/lld/test/wasm/build-id.s b/lld/test/wasm/build-id.s new file mode 100644 --- /dev/null +++ b/lld/test/wasm/build-id.s @@ -0,0 +1,70 @@ +# REQUIRES: wasm + +# RUN: llvm-mc -filetype=obj -triple=wasm32 %s -o %t + +# RUN: wasm-ld --no-entry --build-id %t -o %t2 +# RUN: llvm-objdump -s %t2 | FileCheck --check-prefix=DEFAULT %s +# RUN: wasm-ld --no-entry --build-id=fast %t -o %t2 +# RUN: llvm-objdump -s %t2 | FileCheck --check-prefix=DEFAULT %s +# RUN: wasm-ld --no-entry --build-id %t -o %t2 --threads=1 +# RUN: llvm-objdump -s %t2 | FileCheck --check-prefix=DEFAULT %s + +# RUN: wasm-ld --no-entry --build-id=md5 %t -o %t2 +# RUN: llvm-objdump -s %t2 | FileCheck --check-prefix=MD5 %s +# RUN: wasm-ld --no-entry --build-id=md5 %t -o %t2 --threads=1 +# RUN: llvm-objdump -s %t2 | FileCheck --check-prefix=MD5 %s + +# RUN: wasm-ld --no-entry --build-id=sha1 %t -o %t2 +# RUN: llvm-objdump -s %t2 | FileCheck --check-prefix=SHA1 %s +# RUN: wasm-ld --no-entry --build-id=sha1 %t -o %t2 --threads=1 +# RUN: llvm-objdump -s %t2 | FileCheck --check-prefix=SHA1 %s + +# RUN: wasm-ld --no-entry --build-id=tree %t -o %t2 +# RUN: llvm-objdump -s %t2 | FileCheck --check-prefix=SHA1 %s +# RUN: wasm-ld --no-entry --build-id=tree %t -o %t2 --threads=1 +# RUN: llvm-objdump -s %t2 | FileCheck --check-prefix=SHA1 %s + +# RUN: wasm-ld --no-entry --build-id=uuid %t -o %t2 +# RUN: llvm-objdump -s %t2 | FileCheck --check-prefix=UUID %s + +# RUN: wasm-ld --no-entry --build-id=0x12345678 %t -o %t2 +# RUN: llvm-objdump -s %t2 | FileCheck --check-prefix=HEX %s + +# RUN: wasm-ld --no-entry %t -o %t2 +# RUN: llvm-objdump -s %t2 | FileCheck --check-prefix=NONE %s + +# RUN: wasm-ld --no-entry --build-id=md5 --build-id=none %t -o %t2 +# RUN: llvm-objdump -s %t2 | FileCheck --check-prefix=NONE %s +# RUN: wasm-ld --no-entry --build-id --build-id=none %t -o %t2 +# RUN: llvm-objdump -s %t2 | FileCheck --check-prefix=NONE %s +# RUN: wasm-ld --no-entry --build-id=none --build-id %t -o %t2 +# RUN: llvm-objdump -s %t2 | FileCheck --check-prefix=DEFAULT %s + +.section .data.foo,"",@ + .globl foo + .hidden foo + .p2align 2 +foo: + .int32 1 + .size foo, 4 + + +# DEFAULT: Contents of section build_id: +# DEFAULT-NEXT: 0000 08daac5a a38e6ff4 34 ...Z..o.4 + +# MD5: Contents of section build_id: +# MD5-NEXT: 0000 10330e2c fa17b440 be2b4c77 65a34d23 .3.,...@.+Lwe.M# +# MD5-NEXT: 0010 eb . + +# SHA1: Contents of section build_id: +# SHA1-NEXT: 0000 1405004d 2168aadb fc23e338 9bee8c16 ...M!h...#.8.... +# SHA1-NEXT: 0010 71c65fca 85 q._.. + +# UUID: Contents of section build_id: +# UUID-NEXT: 0000 10 + +# HEX: Contents of section build_id: +# HEX-NEXT: 0000 04123456 78 ..4Vx + + +# NONE-NOT: Contents of section build_id: diff --git a/lld/wasm/Config.h b/lld/wasm/Config.h --- a/lld/wasm/Config.h +++ b/lld/wasm/Config.h @@ -20,6 +20,9 @@ // For --unresolved-symbols. enum class UnresolvedPolicy { ReportError, Warn, Ignore, ImportDynamic }; +// For --build-id. +enum class BuildIdKind { None, Fast, Md5, Sha1, Hexstring, Uuid }; + // This struct contains the global configuration for the linker. // Most fields are direct mapping from the command line options // and such fields have the same name as the corresponding options. @@ -63,6 +66,7 @@ llvm::StringRef thinLTOJobs; bool ltoDebugPassManager; UnresolvedPolicy unresolvedSymbols; + BuildIdKind buildId = BuildIdKind::None; llvm::StringRef entry; llvm::StringRef mapFile; @@ -75,6 +79,7 @@ std::vector searchPaths; llvm::CachePruningPolicy thinLTOCachePolicy; llvm::Optional> features; + std::vector buildIdVector; // The following config options do not directly correspond to any // particular command line options. diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp --- a/lld/wasm/Driver.cpp +++ b/lld/wasm/Driver.cpp @@ -348,6 +348,35 @@ return errorOrWarn; } +// Parse --build-id or --build-id=