[PATCH] D140291: [llvm-objcopy] Use getNumberOfSymbols() instead of getRawNumberOfSymbols()

Daan De Meyer via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 19 04:04:39 PST 2022


DaanDeMeyer created this revision.
DaanDeMeyer added reviewers: drodriguez, MaskRay.
Herald added subscribers: StephenFan, pengfei, abrachet, hiraditya, kristof.beyls.
Herald added a reviewer: alexander-shaposhnikov.
Herald added a reviewer: jhenderson.
Herald added a project: All.
DaanDeMeyer requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

  The first thing we do in the for loop is call getSymbol() which checks
  if the index is greater than or equal to getRawNumberOfSymbols() and returns
  an error if that's the case. Given the above, it makes sense to loop over
  getRawNumberOfSymbols() instead of over getNumberOfSymbols() since the value
  of the former may differ from the latter if the symbol table could not be found.
  
  This patch allows using llvm-objcopy to add sections to a aarch64
  PE executable on x86-64. Before, it failed with an error indicating
  it failed to parse the PE binary.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140291

Files:
  llvm/lib/ObjCopy/COFF/COFFReader.cpp


Index: llvm/lib/ObjCopy/COFF/COFFReader.cpp
===================================================================
--- llvm/lib/ObjCopy/COFF/COFFReader.cpp
+++ llvm/lib/ObjCopy/COFF/COFFReader.cpp
@@ -83,9 +83,9 @@
 
 Error COFFReader::readSymbols(Object &Obj, bool IsBigObj) const {
   std::vector<Symbol> Symbols;
-  Symbols.reserve(COFFObj.getRawNumberOfSymbols());
+  Symbols.reserve(COFFObj.getNumberOfSymbols());
   ArrayRef<Section> Sections = Obj.getSections();
-  for (uint32_t I = 0, E = COFFObj.getRawNumberOfSymbols(); I < E;) {
+  for (uint32_t I = 0, E = COFFObj.getNumberOfSymbols(); I < E;) {
     Expected<COFFSymbolRef> SymOrErr = COFFObj.getSymbol(I);
     if (!SymOrErr)
       return SymOrErr.takeError();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D140291.483903.patch
Type: text/x-patch
Size: 724 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221219/59a1e7b8/attachment.bin>


More information about the llvm-commits mailing list