[PATCH] D56294: [ObjectYAML] [COFF] Support multiple symbols with the same name
Martin Storsjö via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 3 15:08:21 PST 2019
mstorsjo created this revision.
mstorsjo added reviewers: jhenderson, rnk, ruiu, alexshap, zturner.
This is necessary for YAML based tests for D55881 <https://reviews.llvm.org/D55881>.
I'll make tests tomorrow. Is it best to have a composite test of it in test/tools/yaml2obj, that starts with a yaml input, converts to obj and checks it with llvm-readobj, and back to yaml which is partially checked in the same test? That'd avoid having to use a binary input file for the test.
Repository:
rL LLVM
https://reviews.llvm.org/D56294
Files:
include/llvm/ObjectYAML/COFFYAML.h
lib/ObjectYAML/COFFYAML.cpp
tools/obj2yaml/coff2yaml.cpp
tools/yaml2obj/yaml2coff.cpp
Index: tools/yaml2obj/yaml2coff.cpp
===================================================================
--- tools/yaml2obj/yaml2coff.cpp
+++ tools/yaml2obj/yaml2coff.cpp
@@ -529,6 +529,8 @@
: 0);
for (const COFFYAML::Relocation &R : S.Relocations) {
uint32_t SymbolTableIndex = SymbolTableIndexMap[R.SymbolName];
+ if (R.SymbolTableIndex)
+ SymbolTableIndex = *R.SymbolTableIndex;
OS << binary_le(R.VirtualAddress)
<< binary_le(SymbolTableIndex)
<< binary_le(R.Type);
Index: tools/obj2yaml/coff2yaml.cpp
===================================================================
--- tools/obj2yaml/coff2yaml.cpp
+++ tools/obj2yaml/coff2yaml.cpp
@@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
#include "obj2yaml.h"
+#include "llvm/ADT/StringMap.h"
#include "llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h"
#include "llvm/DebugInfo/CodeView/DebugStringTableSubsection.h"
#include "llvm/DebugInfo/CodeView/StringsAndChecksums.h"
@@ -142,6 +143,14 @@
codeview::StringsAndChecksumsRef SC;
initializeFileAndStringTable(Obj, SC);
+ StringMap<size_t> SymbolOccurrances;
+ for (const auto &S : Obj.symbols()) {
+ object::COFFSymbolRef Symbol = Obj.getCOFFSymbol(S);
+ StringRef Name;
+ Obj.getSymbolName(Symbol, Name);
+ SymbolOccurrances[Name]++;
+ }
+
for (const auto &ObjSection : Obj.sections()) {
const object::coff_section *COFFSection = Obj.getCOFFSection(ObjSection);
COFFYAML::Section NewYAMLSection;
@@ -192,7 +201,10 @@
OS.flush();
report_fatal_error(Buf);
}
- Rel.SymbolName = *SymbolNameOrErr;
+ if (SymbolOccurrances[*SymbolNameOrErr] == 1)
+ Rel.SymbolName = *SymbolNameOrErr;
+ else
+ Rel.SymbolTableIndex = reloc->SymbolTableIndex;
Rel.VirtualAddress = reloc->VirtualAddress;
Rel.Type = reloc->Type;
Relocations.push_back(Rel);
Index: lib/ObjectYAML/COFFYAML.cpp
===================================================================
--- lib/ObjectYAML/COFFYAML.cpp
+++ lib/ObjectYAML/COFFYAML.cpp
@@ -407,7 +407,8 @@
void MappingTraits<COFFYAML::Relocation>::mapping(IO &IO,
COFFYAML::Relocation &Rel) {
IO.mapRequired("VirtualAddress", Rel.VirtualAddress);
- IO.mapRequired("SymbolName", Rel.SymbolName);
+ IO.mapOptional("SymbolName", Rel.SymbolName, StringRef());
+ IO.mapOptional("SymbolTableIndex", Rel.SymbolTableIndex);
COFF::header &H = *static_cast<COFF::header *>(IO.getContext());
if (H.Machine == COFF::IMAGE_FILE_MACHINE_I386) {
Index: include/llvm/ObjectYAML/COFFYAML.h
===================================================================
--- include/llvm/ObjectYAML/COFFYAML.h
+++ include/llvm/ObjectYAML/COFFYAML.h
@@ -59,6 +59,7 @@
uint32_t VirtualAddress;
uint16_t Type;
StringRef SymbolName;
+ Optional<uint32_t> SymbolTableIndex;
};
struct Section {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56294.180151.patch
Type: text/x-patch
Size: 3042 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190103/0cf4ffa0/attachment.bin>
More information about the llvm-commits
mailing list