summaryrefslogtreecommitdiff
path: root/llvm/lib/ObjectYAML/MachOEmitter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/ObjectYAML/MachOEmitter.cpp')
-rw-r--r--llvm/lib/ObjectYAML/MachOEmitter.cpp46
1 files changed, 15 insertions, 31 deletions
diff --git a/llvm/lib/ObjectYAML/MachOEmitter.cpp b/llvm/lib/ObjectYAML/MachOEmitter.cpp
index 680264484704..dec9c9f6960b 100644
--- a/llvm/lib/ObjectYAML/MachOEmitter.cpp
+++ b/llvm/lib/ObjectYAML/MachOEmitter.cpp
@@ -29,7 +29,7 @@ namespace {
class MachOWriter {
public:
- MachOWriter(MachOYAML::Object &Obj) : Obj(Obj), is64Bit(true), fileStart(0) {
+ MachOWriter(MachOYAML::Object &Obj) : Obj(Obj), fileStart(0) {
is64Bit = Obj.Header.magic == MachO::MH_MAGIC_64 ||
Obj.Header.magic == MachO::MH_CIGAM_64;
memset(reinterpret_cast<void *>(&Header), 0, sizeof(MachO::mach_header_64));
@@ -199,14 +199,12 @@ size_t writeLoadCommandData<MachO::build_version_command>(
}
void ZeroFillBytes(raw_ostream &OS, size_t Size) {
- std::vector<uint8_t> FillData;
- FillData.insert(FillData.begin(), Size, 0);
+ std::vector<uint8_t> FillData(Size, 0);
OS.write(reinterpret_cast<char *>(FillData.data()), Size);
}
void Fill(raw_ostream &OS, size_t Size, uint32_t Data) {
- std::vector<uint32_t> FillData;
- FillData.insert(FillData.begin(), (Size / 4) + 1, Data);
+ std::vector<uint32_t> FillData((Size / 4) + 1, Data);
OS.write(reinterpret_cast<char *>(FillData.data()), Size);
}
@@ -285,34 +283,20 @@ Error MachOWriter::writeSectionData(raw_ostream &OS) {
return createStringError(
errc::invalid_argument,
"wrote too much data somewhere, section offsets don't line up");
- if (0 == strncmp(&Sec.segname[0], "__DWARF", 16)) {
- Error Err = Error::success();
- cantFail(std::move(Err));
- if (0 == strncmp(&Sec.sectname[0], "__debug_str", 16))
- Err = DWARFYAML::emitDebugStr(OS, Obj.DWARF);
- else if (0 == strncmp(&Sec.sectname[0], "__debug_abbrev", 16))
- Err = DWARFYAML::emitDebugAbbrev(OS, Obj.DWARF);
- else if (0 == strncmp(&Sec.sectname[0], "__debug_aranges", 16))
- Err = DWARFYAML::emitDebugAranges(OS, Obj.DWARF);
- else if (0 == strncmp(&Sec.sectname[0], "__debug_ranges", 16))
- Err = DWARFYAML::emitDebugRanges(OS, Obj.DWARF);
- else if (0 == strncmp(&Sec.sectname[0], "__debug_pubnames", 16)) {
- if (Obj.DWARF.PubNames)
- Err = DWARFYAML::emitPubSection(OS, *Obj.DWARF.PubNames,
- Obj.IsLittleEndian);
- } else if (0 == strncmp(&Sec.sectname[0], "__debug_pubtypes", 16)) {
- if (Obj.DWARF.PubTypes)
- Err = DWARFYAML::emitPubSection(OS, *Obj.DWARF.PubTypes,
- Obj.IsLittleEndian);
- } else if (0 == strncmp(&Sec.sectname[0], "__debug_info", 16))
- Err = DWARFYAML::emitDebugInfo(OS, Obj.DWARF);
- else if (0 == strncmp(&Sec.sectname[0], "__debug_line", 16))
- Err = DWARFYAML::emitDebugLine(OS, Obj.DWARF);
-
- if (Err)
+ StringRef SectName(Sec.sectname,
+ strnlen(Sec.sectname, sizeof(Sec.sectname)));
+ // If the section's content is specified in the 'DWARF' entry, we will
+ // emit it regardless of the section's segname.
+ if (Obj.DWARF.getNonEmptySectionNames().count(SectName.substr(2))) {
+ if (Sec.content)
+ return createStringError(errc::invalid_argument,
+ "cannot specify section '" + SectName +
+ "' contents in the 'DWARF' entry and "
+ "the 'content' at the same time");
+ auto EmitFunc = DWARFYAML::getDWARFEmitterByName(SectName.substr(2));
+ if (Error Err = EmitFunc(OS, Obj.DWARF))
return Err;
-
continue;
}