Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[lld] select a default eflags for hexagon #108431

Merged
merged 1 commit into from
Sep 13, 2024

Conversation

androm3da
Copy link
Member

Empty archives are apparently routine in linux kernel builds, so instead of asserting, we should handle this case with a sane default value.

@llvmbot
Copy link
Member

llvmbot commented Sep 12, 2024

@llvm/pr-subscribers-lld

@llvm/pr-subscribers-backend-hexagon

Author: Brian Cain (androm3da)

Changes

Empty archives are apparently routine in linux kernel builds, so instead of asserting, we should handle this case with a sane default value.


Full diff: https://github.com/llvm/llvm-project/pull/108431.diff

2 Files Affected:

  • (modified) lld/ELF/Arch/Hexagon.cpp (+4-4)
  • (modified) lld/test/ELF/hexagon-eflag.s (+5)
diff --git a/lld/ELF/Arch/Hexagon.cpp b/lld/ELF/Arch/Hexagon.cpp
index 54821c299bde9e..71169477230128 100644
--- a/lld/ELF/Arch/Hexagon.cpp
+++ b/lld/ELF/Arch/Hexagon.cpp
@@ -60,17 +60,17 @@ Hexagon::Hexagon() {
 }
 
 uint32_t Hexagon::calcEFlags() const {
-  assert(!ctx.objectFiles.empty());
+  static uint32_t DEFAULT_ARCH_REV = 0x60;
 
   // The architecture revision must always be equal to or greater than
   // greatest revision in the list of inputs.
-  uint32_t ret = 0;
+  std::optional<uint32_t> ret;
   for (InputFile *f : ctx.objectFiles) {
     uint32_t eflags = cast<ObjFile<ELF32LE>>(f)->getObj().getHeader().e_flags;
-    if (eflags > ret)
+    if (!ret || eflags > *ret)
       ret = eflags;
   }
-  return ret;
+  return ret.value_or(DEFAULT_ARCH_REV);
 }
 
 static uint32_t applyMask(uint32_t mask, uint32_t data) {
diff --git a/lld/test/ELF/hexagon-eflag.s b/lld/test/ELF/hexagon-eflag.s
index 01cb5e5b0f2935..dbe8604f69fda3 100644
--- a/lld/test/ELF/hexagon-eflag.s
+++ b/lld/test/ELF/hexagon-eflag.s
@@ -5,3 +5,8 @@
 # RUN: llvm-readelf -h  %t3 | FileCheck %s
 # Verify that the largest arch in the input list is selected.
 # CHECK: Flags: 0x62
+
+# RUN: llvm-ar rcsD %t4
+# RUN: ld.lld -m hexagonelf %t4 -o %t5
+# RUN: llvm-readelf -h  %t5 | FileCheck --check-prefix=CHECK-EMPTYARCHIVE %s
+# CHECK-EMPTYARCHIVE: Flags: 0x60

@androm3da androm3da force-pushed the bcain/lld_default_eflag branch from 648a827 to 47c76c0 Compare September 12, 2024 19:20
@@ -60,17 +60,17 @@ Hexagon::Hexagon() {
}

uint32_t Hexagon::calcEFlags() const {
assert(!ctx.objectFiles.empty());
static const uint32_t DEFAULT_ARCH_REV = 0x60;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable name does not follow the convention. Since this variable is only used once, you can inline it and add a comment.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing it out. Fixed.

Empty archives are apparently routine in linux kernel builds, so
instead of asserting, we should handle this case with a sane default
value.
@androm3da androm3da force-pushed the bcain/lld_default_eflag branch from 47c76c0 to ea49faa Compare September 13, 2024 03:19
@quic-akaryaki quic-akaryaki self-requested a review September 13, 2024 22:00
@androm3da androm3da merged commit d1ba432 into llvm:main Sep 13, 2024
8 checks passed
llvmbot pushed a commit to llvmbot/llvm-project that referenced this pull request Sep 13, 2024
Empty archives are apparently routine in linux kernel builds, so instead
of asserting, we should handle this case with a sane default value.

(cherry picked from commit d1ba432)
tru pushed a commit to llvmbot/llvm-project that referenced this pull request Sep 16, 2024
Empty archives are apparently routine in linux kernel builds, so instead
of asserting, we should handle this case with a sane default value.

(cherry picked from commit d1ba432)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants