[llvm] 2e0c460 - [Object][COFF] Improve section name parsing
Pengxuan Zheng via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 16 17:01:27 PDT 2022
Author: Pengxuan Zheng
Date: 2022-06-16T17:01:10-07:00
New Revision: 2e0c46044a5df9420375d73b25524b47db02a00f
URL: https://github.com/llvm/llvm-project/commit/2e0c46044a5df9420375d73b25524b47db02a00f
DIFF: https://github.com/llvm/llvm-project/commit/2e0c46044a5df9420375d73b25524b47db02a00f.diff
LOG: [Object][COFF] Improve section name parsing
Inspired by discussions on 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.
Reviewed By: rnk
Differential Revision: https://reviews.llvm.org/D127902
Added:
Modified:
llvm/lib/Object/COFFObjectFile.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Object/COFFObjectFile.cpp b/llvm/lib/Object/COFFObjectFile.cpp
index ee5411d0aa01..1a4bb329201a 100644
--- a/llvm/lib/Object/COFFObjectFile.cpp
+++ b/llvm/lib/Object/COFFObjectFile.cpp
@@ -1146,13 +1146,7 @@ uint32_t COFFObjectFile::getSymbolIndex(COFFSymbolRef Symbol) const {
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("/")) {
@@ -1162,7 +1156,7 @@ COFFObjectFile::getSectionName(const coff_section *Sec) const {
return createStringError(object_error::parse_failed,
"invalid section name");
} else {
- if (Name.substr(1).consumeInteger(10, Offset))
+ if (Name.substr(1).getAsInteger(10, Offset))
return createStringError(object_error::parse_failed,
"invalid section name");
}
More information about the llvm-commits
mailing list