[PATCH] D81051: [ObjectYAML][ELF] Let the endianness be inferred from FileHeader.

Xing GUO via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 2 20:48:56 PDT 2020


Higuoxing created this revision.
Higuoxing added reviewers: jhenderson, grimar, MaskRay.
Herald added subscribers: llvm-commits, hiraditya, aprantl, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.
Higuoxing added a parent revision: D80972: [ObjectYAML][DWARF] Support emitting the .debug_aranges section in ELFYAML..

This patch helps infer the endianness of DWARF sections from `FileHeader`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81051

Files:
  llvm/lib/ObjectYAML/ELFYAML.cpp
  llvm/test/tools/yaml2obj/ELF/DWARF/debug-aranges.yaml


Index: llvm/test/tools/yaml2obj/ELF/DWARF/debug-aranges.yaml
===================================================================
--- llvm/test/tools/yaml2obj/ELF/DWARF/debug-aranges.yaml
+++ llvm/test/tools/yaml2obj/ELF/DWARF/debug-aranges.yaml
@@ -4,8 +4,8 @@
 
 ## Generate and verify a big endian object file.
 
-# RUN: yaml2obj --docnum=1 -DENDIAN=ELFDATA2MSB %s -o %t1.o
-# RUN: llvm-readobj --sections --section-data %t1.o | \
+# RUN: yaml2obj --docnum=1 -DENDIAN=ELFDATA2MSB %s -o %t.be.o
+# RUN: llvm-readobj --sections --section-data %t.be.o | \
 # RUN:   FileCheck %s -DADDRALIGN=1 --check-prefixes=DWARF-BE-DEFAULT
 
 #      DWARF-BE-DEFAULT: Section {
@@ -88,6 +88,65 @@
         - Address: 0x0000000000005678
           Length:  0x20
 
+## Generate and verify a little endian object file.
+
+# RUN: yaml2obj --docnum=1 -DENDIAN=ELFDATA2LSB %s -o %t.le.o
+# RUN: llvm-readobj --sections --section-data %t.le.o | \
+# RUN:   FileCheck %s --check-prefixes=DWARF-LE-DEFAULT
+
+#      DWARF-LE-DEFAULT: Section {
+#      DWARF-LE-DEFAULT:   Index: 1
+# DWARF-LE-DEFAULT-NEXT:   Name: .debug_aranges (1)
+# DWARF-LE-DEFAULT-NEXT:   Type: SHT_PROGBITS (0x1)
+# DWARF-LE-DEFAULT-NEXT:   Flags [ (0x0)
+# DWARF-LE-DEFAULT-NEXT:   ]
+# DWARF-LE-DEFAULT-NEXT:   Address: 0x0
+# DWARF-LE-DEFAULT-NEXT:   Offset: 0x40
+# DWARF-LE-DEFAULT-NEXT:   Size: 96
+# DWARF-LE-DEFAULT-NEXT:   Link: 0
+# DWARF-LE-DEFAULT-NEXT:   Info: 0
+# DWARF-LE-DEFAULT-NEXT:   AddressAlignment: 1
+# DWARF-LE-DEFAULT-NEXT:   EntrySize: 0
+# DWARF-LE-DEFAULT-NEXT:   SectionData (
+# DWARF-LE-DEFAULT-NEXT:     0000: 2C000000 02000000 00000800 00000000
+##                                 |        |   |        | |  |
+##                                 |        |   |        | |  +------- Padding zeros (4-byte)
+##                                 |        |   |        | +- SegSize (1-byte) 0x00
+##                                 |        |   |        +- AddrSize (1-byte) 0x08
+##                                 |        |   +--- ---- CuOffset (4-byte) 0x00
+##                                 |        +--- Version (2-byte) 0x02
+##                                 +------- InitialLength (4-byte) 0x2c
+##
+# DWARF-LE-DEFAULT-NEXT:     0010: 34120000 00000000 20000000 00000000
+##                                 |                 |
+##                                 |                 +---------------- Length (8-byte) 0x20
+##                                 +------- -------- Address (8-byte) 0x1234
+##
+# DWARF-LE-DEFAULT-NEXT:     0020: 00000000 00000000 00000000 00000000
+##                                 |
+##                                 +------- -------- -------- -------- Terminating entry
+##
+# DWARF-LE-DEFAULT-NEXT:     0030: 2C000000 02006500 00000800 00000000
+##                                 |        |   |        | |  |
+##                                 |        |   |        | |  +------- Padding zeros (4-byte)
+##                                 |        |   |        | +- SegSize (1-byte) 0x00
+##                                 |        |   |        +- AddrSize (1-byte) 0x08
+##                                 |        |   +--- ---- CuOffset (4-byte) 0x65
+##                                 |        +--- Version (2-byte) 0x02
+##                                 +------- InitialLength (4-byte) 0x2c
+##
+# DWARF-LE-DEFAULT-NEXT:     0040: 78560000 00000000 20000000 00000000
+##                                 |                 |
+##                                 |                 +---------------- Length (8-byte) 0x20
+##                                 +------- -------- Address (8-byte) 0x5678
+##
+# DWARF-LE-DEFAULT-NEXT:     0050: 00000000 00000000 00000000 00000000
+##                                 |
+##                                 +------- -------- -------- -------- Terminating entry
+##
+# DWARF-LE-DEFAULT-NEXT:   )
+# DWARF-LE-DEFAULT-NEXT: }
+
 ## b) Generate the .debug_aranges section from raw section content.
 
 # RUN: yaml2obj --docnum=2 %s -o %t2.o
Index: llvm/lib/ObjectYAML/ELFYAML.cpp
===================================================================
--- llvm/lib/ObjectYAML/ELFYAML.cpp
+++ llvm/lib/ObjectYAML/ELFYAML.cpp
@@ -1654,6 +1654,9 @@
   IO.mapOptional("Symbols", Object.Symbols);
   IO.mapOptional("DynamicSymbols", Object.DynamicSymbols);
   IO.mapOptional("DWARF", Object.DWARF);
+  if (Object.DWARF)
+    Object.DWARF->IsLittleEndian =
+        Object.Header.Data == ELFYAML::ELF_ELFDATA(ELF::ELFDATA2LSB);
   IO.setContext(nullptr);
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D81051.268045.patch
Type: text/x-patch
Size: 4516 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200603/9b0f16b1/attachment.bin>


More information about the llvm-commits mailing list