Skip to content

Commit d1ba432

Browse files
authored
[lld] select a default eflags for hexagon (#108431)
Empty archives are apparently routine in linux kernel builds, so instead of asserting, we should handle this case with a sane default value.
1 parent e1bd974 commit d1ba432

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

lld/ELF/Arch/Hexagon.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,15 @@ Hexagon::Hexagon() {
6060
}
6161

6262
uint32_t Hexagon::calcEFlags() const {
63-
assert(!ctx.objectFiles.empty());
64-
6563
// The architecture revision must always be equal to or greater than
6664
// greatest revision in the list of inputs.
67-
uint32_t ret = 0;
65+
std::optional<uint32_t> ret;
6866
for (InputFile *f : ctx.objectFiles) {
6967
uint32_t eflags = cast<ObjFile<ELF32LE>>(f)->getObj().getHeader().e_flags;
70-
if (eflags > ret)
68+
if (!ret || eflags > *ret)
7169
ret = eflags;
7270
}
73-
return ret;
71+
return ret.value_or(/* Default Arch Rev: */ 0x60);
7472
}
7573

7674
static uint32_t applyMask(uint32_t mask, uint32_t data) {

lld/test/ELF/hexagon-eflag.s

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,8 @@
55
# RUN: llvm-readelf -h %t3 | FileCheck %s
66
# Verify that the largest arch in the input list is selected.
77
# CHECK: Flags: 0x62
8+
9+
# RUN: llvm-ar rcsD %t4
10+
# RUN: ld.lld -m hexagonelf %t4 -o %t5
11+
# RUN: llvm-readelf -h %t5 | FileCheck --check-prefix=CHECK-EMPTYARCHIVE %s
12+
# CHECK-EMPTYARCHIVE: Flags: 0x60

0 commit comments

Comments
 (0)