[llvm] Reapply "Allow "[[FLAGS=<none>]]" value in the ELF Fileheader Flags field (#143845)" (PR #151094)

Aakanksha Patil via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 4 11:25:17 PDT 2025


================
@@ -281,7 +281,8 @@ template <class ELFT> Expected<ELFYAML::Object *> ELFDumper<ELFT>::dump() {
   Y->Header.Type = Obj.getHeader().e_type;
   if (Obj.getHeader().e_machine != 0)
     Y->Header.Machine = ELFYAML::ELF_EM(Obj.getHeader().e_machine);
-  Y->Header.Flags = Obj.getHeader().e_flags;
+  if (Obj.getHeader().e_flags != 0)
+    Y->Header.Flags = ELFYAML::ELF_EF(Obj.getHeader().e_flags);
----------------
aakanksha555 wrote:

With the old patch on a release build I found all lit tests passing but with assertions enabled it was causing a lot of tests to crash.
This is the assertion I saw - 

`void llvm::yaml::IO::processKeyWithDefault(const char*, ELFYAML::ELF_EF; Context = llvm::yaml::EmptyContext]: Assertion `!DefaultValue && "std::optional<T> shouldn't have a value!"' failed.
`
So, I made the Flags field fully optional like the Machine field by removing the default value in llvm/lib/ObjectYAML/ELFYAML.cpp
The asserts still fired even with this change.
Adding the ELFYAML::ELF_EF cast where the Flags value is assigned was able to fix the asserts.

https://github.com/llvm/llvm-project/pull/151094


More information about the llvm-commits mailing list