[PATCH] D107324: [llvm-objcopy] [COFF] Do not patch debug entries with Repro type

Pirama Arumuga Nainar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 2 22:48:17 PDT 2021


pirama created this revision.
pirama added reviewers: mstorsjo, jhenderson.
Herald added a reviewer: alexander-shaposhnikov.
Herald added a reviewer: rupprecht.
Herald added a subscriber: abrachet.
pirama requested review of this revision.
Herald added subscribers: llvm-commits, MaskRay.
Herald added a project: LLVM.

Fix an edge case missed by https://reviews.llvm.org/D78921.  The Repro
debug entry (generated with the /Brepro linker flag) does not have a
debug-directory payload.  Do not attempt to patch Debug entries of this
type.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107324

Files:
  llvm/test/tools/llvm-objcopy/COFF/strip-brepro.test
  llvm/tools/llvm-objcopy/COFF/Writer.cpp


Index: llvm/tools/llvm-objcopy/COFF/Writer.cpp
===================================================================
--- llvm/tools/llvm-objcopy/COFF/Writer.cpp
+++ llvm/tools/llvm-objcopy/COFF/Writer.cpp
@@ -426,15 +426,17 @@
       uint8_t *End = Ptr + Dir->Size;
       while (Ptr < End) {
         debug_directory *Debug = reinterpret_cast<debug_directory *>(Ptr);
-        if (!Debug->AddressOfRawData)
-          return createStringError(object_error::parse_failed,
-                                   "debug directory payload outside of "
-                                   "mapped sections not supported");
-        if (Expected<uint32_t> FilePosOrErr =
-                virtualAddressToFileAddress(Debug->AddressOfRawData))
-          Debug->PointerToRawData = *FilePosOrErr;
-        else
-          return FilePosOrErr.takeError();
+        if (Debug->Type != COFF::IMAGE_DEBUG_TYPE_REPRO) {
+          if (!Debug->AddressOfRawData)
+            return createStringError(object_error::parse_failed,
+                                     "debug directory payload outside of "
+                                     "mapped sections not supported");
+          if (Expected<uint32_t> FilePosOrErr =
+                  virtualAddressToFileAddress(Debug->AddressOfRawData))
+            Debug->PointerToRawData = *FilePosOrErr;
+          else
+            return FilePosOrErr.takeError();
+        }
         Ptr += sizeof(debug_directory);
         Offset += sizeof(debug_directory);
       }
Index: llvm/test/tools/llvm-objcopy/COFF/strip-brepro.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-objcopy/COFF/strip-brepro.test
@@ -0,0 +1,44 @@
+## Check that 'Repro' debug entry's non-existent debug directory payload is
+## handled correctly by `llvm-objcopy -S -x`.
+
+# RUN: yaml2obj %s -o %t.exe
+# RUN: llvm-objcopy -S -x %t.exe
+
+--- !COFF
+OptionalHeader:
+  AddressOfEntryPoint: 4096
+  ImageBase:       1073741824
+  SectionAlignment: 4096
+  FileAlignment:   512
+  MajorOperatingSystemVersion: 6
+  MinorOperatingSystemVersion: 0
+  MajorImageVersion: 0
+  MinorImageVersion: 0
+  MajorSubsystemVersion: 6
+  MinorSubsystemVersion: 0
+  Subsystem:       IMAGE_SUBSYSTEM_WINDOWS_CUI
+  DLLCharacteristics: [  ]
+  SizeOfStackReserve: 1048576
+  SizeOfStackCommit: 4096
+  SizeOfHeapReserve: 1048576
+  SizeOfHeapCommit: 4096
+  Debug:
+    RelativeVirtualAddress: 8192
+    Size:            28
+header:
+  Machine:         IMAGE_FILE_MACHINE_AMD64
+  Characteristics: [  ]
+sections:
+  - Name:            .text
+    Characteristics: [  ]
+    VirtualAddress:  4096
+    VirtualSize:     3
+    SectionData:     31C0C3
+  - Name:            .rdata
+    Characteristics: [  ]
+    VirtualAddress:  8192
+    VirtualSize:     28
+    ## '10' in SectionData below indicates the Repro debug entry type.
+    SectionData:     0000000047F96B200000000010000000000000000000000000000000
+symbols:         []
+...


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107324.363629.patch
Type: text/x-patch
Size: 2985 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210803/3540f147/attachment.bin>


More information about the llvm-commits mailing list