[PATCH] D127902: [Object][COFF] Improve section name parsing

Pengxuan Zheng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 15 12:57:58 PDT 2022


pzheng created this revision.
pzheng added reviewers: efriedma, rnk, jhenderson, thieta, thakis, hans, mstorsjo.
Herald added a subscriber: hiraditya.
Herald added a project: All.
pzheng requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Inspired by discussions on D127369 <https://reviews.llvm.org/D127369>, we probably can further improve LLVM's COFF
section name parsing. Hopefully, this makes the logic simpler and handles some
edge cases more elegantly.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127902

Files:
  llvm/lib/Object/COFFObjectFile.cpp


Index: llvm/lib/Object/COFFObjectFile.cpp
===================================================================
--- llvm/lib/Object/COFFObjectFile.cpp
+++ llvm/lib/Object/COFFObjectFile.cpp
@@ -1146,13 +1146,7 @@
 
 Expected<StringRef>
 COFFObjectFile::getSectionName(const coff_section *Sec) const {
-  StringRef Name;
-  if (Sec->Name[COFF::NameSize - 1] == 0)
-    // Null terminated, let ::strlen figure out the length.
-    Name = Sec->Name;
-  else
-    // Not null terminated, use all 8 bytes.
-    Name = StringRef(Sec->Name, COFF::NameSize);
+  StringRef Name = StringRef(Sec->Name, COFF::NameSize).split('\0').first;
 
   // Check for string table entry. First byte is '/'.
   if (Name.startswith("/")) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127902.437307.patch
Type: text/x-patch
Size: 713 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220615/b2b10fba/attachment.bin>


More information about the llvm-commits mailing list