[llvm] [yaml2obj] Don't use uninitialized Type (PR #123274)
James Henderson via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 22 00:52:47 PST 2025
================
@@ -25,3 +25,31 @@ Sections:
Type: 0xabcd
- Name: decimal
Type: 1234
+
+
+# RUN: not yaml2obj %s --docnum=2 -o %t2 2>&1 | FileCheck %s --check-prefix=UNKNOWN-TYPE
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+Sections:
+ - Name: .foo
+ Type: FOO_SECTION
+
+# UNKNOWN-TYPE: error: invalid hex32 number
+
+
+# RUN: not yaml2obj %s --docnum=3 -o %t3 -DMACHINE=EM_NONE 2>&1 | FileCheck %s --check-prefix=UNKNOWN-SHT-TYPE
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+Sections:
+ - Name: .foo
+ Type: SHT_MIPS_ABIFLAGS
----------------
jh7370 wrote:
1) I'd be more explicit and say `SHT_UNKNOWN_TYPE` or similar, since it might not be obvious to the casual reader why this section type is unknown (since `SHT_MIPS_ABIFLAGS` is a valid type for some cases).
2) You can use yaml2obj's -D option to parameterise the YAML, to avoid needing to duplicate the majority of the document for the two unknown cases. Specifically, if you do something like `yaml2obj ... -D SectionType=FOO_SECTION` and then change the `Type` line to (I think - need to double-check the exact syntax) `Type: [[SectionType]]` you don't need the second new YAML document.
https://github.com/llvm/llvm-project/pull/123274
More information about the llvm-commits
mailing list