[llvm] [Object][ELF] Fix section header zero check (PR #181796)

via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 19 00:51:02 PST 2026


================
@@ -935,9 +934,15 @@ template <class ELFT> ELFFile<ELFT>::ELFFile(StringRef Object) : Buf(Object) {}
 template <class ELFT> Error ELFFile<ELFT>::readShdrZero() {
   const Elf_Ehdr &Header = getHeader();
 
-  if ((Header.e_phnum == ELF::PN_XNUM || Header.e_shnum == 0 ||
-       Header.e_shstrndx == ELF::SHN_XINDEX) &&
-      Header.e_shoff != 0) {
+  // If e_shnum == 0 && e_shoff == 0, this indicates that there are no sections,
+  // which is valid for an ELF file.
+  //
+  // However, if e_phnum == PN_XNUM or e_shstrndx == SHN_XINDEX while
+  // e_shoff == 0, the file is inconsistent. In that case, an error will be
----------------
aokblast wrote:

Done. Thanks!

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


More information about the llvm-commits mailing list