Skip to content

Commit 1d96e4b

Browse files
[ELF] Change build-id default to sha1 (#93943)
The current default, build-id=fast, is only 8 bytes due to the usage of 64-bit XXH3. This is incompatible with RPM packaging tools which requires >=16 bytes [1]. In Clang the ENABLE_LINKER_BUILD_ID define makes it pass --build-id without a specific hash type. When also defaulting to LLD, this provides a pretty broken default out-of-box. Using XXH3 was a considerable performance advantage when build-id was first implemented, because sha1 was really sha1 and rather slow. Nowadays sha1 is just 160-bit BLAKE3 which is decently fast and not cryptographically broken, so it should be a good default. Note that the default remains "fast" for wasm because sha1 for wasm is still real sha1. Close #43483. [1]: https://github.com/rpm-software-management/rpm/blob/b7d427728b8ba8734ba47d51849a5736bdd727cd/build/files.c#L1883
1 parent caf2de7 commit 1d96e4b

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

lld/ELF/Options.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def Bstatic: F<"Bstatic">, HelpText<"Do not link against shared libraries">;
5757

5858
def build_id: J<"build-id=">, HelpText<"Generate build ID note">,
5959
MetaVarName<"[fast,md5,sha1,uuid,0x<hexstring>]">;
60-
def : F<"build-id">, Alias<build_id>, AliasArgs<["fast"]>, HelpText<"Alias for --build-id=fast">;
60+
def : F<"build-id">, Alias<build_id>, AliasArgs<["sha1"]>, HelpText<"Alias for --build-id=sha1">;
6161

6262
defm check_sections: B<"check-sections",
6363
"Check section addresses for overlaps (default)",

lld/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ ELF Improvements
4848
and combine relocation sections if their relocated section group members are
4949
placed to the same output section.
5050
(`#94704 <https://github.com/llvm/llvm-project/pull/94704>`_)
51+
* ``--build-id`` now defaults to generating a 20-byte digest ("sha1") instead
52+
of 8-byte ("fast"). This improves compatibility with RPM packaging tools.
53+
(`#93943 <https://github.com/llvm/llvm-project/pull/93943>`_)
5154

5255
Breaking changes
5356
----------------

lld/docs/ld.lld.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ are calculated from the object contents.
119119
is not intended to be cryptographically secure.
120120
.It Fl -build-id
121121
Synonym for
122-
.Fl -build-id Ns = Ns Cm fast .
122+
.Fl -build-id Ns = Ns Cm sha1 .
123123
.It Fl -call-graph-profile-sort Ns = Ns Ar algorithm
124124
.Ar algorithm
125125
may be:

lld/test/ELF/build-id.s

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
# RUN: llvm-readobj -S %t2 | FileCheck -check-prefix=ALIGN %s
77

88
# RUN: ld.lld --build-id %t -o %t2
9-
# RUN: llvm-objdump -s %t2 | FileCheck --check-prefix=DEFAULT %s
10-
# RUN: ld.lld --build-id=fast %t -o %t2
11-
# RUN: llvm-objdump -s %t2 | FileCheck --check-prefix=DEFAULT %s
9+
# RUN: llvm-objdump -s %t2 | FileCheck --check-prefix=SHA1 %s
1210
# RUN: ld.lld --build-id %t -o %t2 --threads=1
13-
# RUN: llvm-objdump -s %t2 | FileCheck --check-prefix=DEFAULT %s
11+
# RUN: llvm-objdump -s %t2 | FileCheck --check-prefix=SHA1 %s
12+
13+
# RUN: ld.lld --build-id=fast %t -o %t2
14+
# RUN: llvm-objdump -s %t2 | FileCheck --check-prefix=FAST %s
1415

1516
# RUN: ld.lld --build-id=md5 %t -o %t2
1617
# RUN: llvm-objdump -s %t2 | FileCheck --check-prefix=MD5 %s
@@ -41,7 +42,7 @@
4142
# RUN: ld.lld --build-id --build-id=none %t -o %t2
4243
# RUN: llvm-objdump -s %t2 | FileCheck --check-prefix=NONE %s
4344
# RUN: ld.lld --build-id=none --build-id %t -o %t2
44-
# RUN: llvm-objdump -s %t2 | FileCheck --check-prefix=DEFAULT %s
45+
# RUN: llvm-objdump -s %t2 | FileCheck --check-prefix=SHA1 %s
4546

4647
.globl _start
4748
_start:
@@ -62,10 +63,10 @@ _start:
6263
# ALIGN-NEXT: Info:
6364
# ALIGN-NEXT: AddressAlignment: 4
6465

65-
# DEFAULT: Contents of section .note.test:
66-
# DEFAULT: Contents of section .note.gnu.build-id:
67-
# DEFAULT-NEXT: 04000000 08000000 03000000 474e5500 ............GNU.
68-
# DEFAULT-NEXT: 630bc2f5 a2584763
66+
# FAST: Contents of section .note.test:
67+
# FAST: Contents of section .note.gnu.build-id:
68+
# FAST-NEXT: 04000000 08000000 03000000 474e5500 ............GNU.
69+
# FAST-NEXT: 630bc2f5 a2584763
6970

7071
# MD5: Contents of section .note.gnu.build-id:
7172
# MD5-NEXT: 04000000 10000000 03000000 474e5500 ............GNU.

0 commit comments

Comments
 (0)