[llvm] d95f8e7 - [yaml2obj][MachO] - Fix PubName/PubType handling.
Georgii Rymar via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 12 02:04:11 PDT 2020
Author: Georgii Rymar
Date: 2020-06-12T12:03:51+03:00
New Revision: d95f8e7aef79393fbb95b8483c9f494da75b1d83
URL: https://github.com/llvm/llvm-project/commit/d95f8e7aef79393fbb95b8483c9f494da75b1d83
DIFF: https://github.com/llvm/llvm-project/commit/d95f8e7aef79393fbb95b8483c9f494da75b1d83.diff
LOG: [yaml2obj][MachO] - Fix PubName/PubType handling.
`PubName` and `PubType` are optional fields since D80722.
They are defined as:
Optional<PubSection> PubNames;
Optional<PubSection> PubTypes;
And initialized in the following way:
IO.mapOptional("debug_pubnames", DWARF.PubNames);
IO.mapOptional("debug_pubtypes", DWARF.PubTypes);
But problem is that because of the issue in `YAMLTraits.cpp`,
when there are no `debug_pubnames`/`debug_pubtypes` keys in a YAML description,
they are not initialized to `Optional::None` as the code expects, but they
are initialized to default `PubSection()` instances.
Because of this, the `if` condition in the following code is always true:
if (Obj.DWARF.PubNames)
Err = DWARFYAML::emitPubSection(OS, *Obj.DWARF.PubNames,
Obj.IsLittleEndian);
What means `emitPubSection` is always called and it writes few values.
This patch fixes the issue. I've reduced `sizeofcmds` by size of data
previously written because of this bug.
Differential revision: https://reviews.llvm.org/D81686
Added:
Modified:
llvm/lib/Support/YAMLTraits.cpp
llvm/test/ObjectYAML/MachO/DWARF-pubsections.yaml
Removed:
################################################################################
diff --git a/llvm/lib/Support/YAMLTraits.cpp b/llvm/lib/Support/YAMLTraits.cpp
index f27be3e97430..752fab2be9b3 100644
--- a/llvm/lib/Support/YAMLTraits.cpp
+++ b/llvm/lib/Support/YAMLTraits.cpp
@@ -166,6 +166,8 @@ bool Input::preflightKey(const char *Key, bool Required, bool, bool &UseDefault,
if (!MN) {
if (Required || !isa<EmptyHNode>(CurrentNode))
setError(CurrentNode, "not a mapping");
+ else
+ UseDefault = true;
return false;
}
MN->ValidKeys.push_back(Key);
diff --git a/llvm/test/ObjectYAML/MachO/DWARF-pubsections.yaml b/llvm/test/ObjectYAML/MachO/DWARF-pubsections.yaml
index 4faac060c8a5..0bc510dca5f0 100644
--- a/llvm/test/ObjectYAML/MachO/DWARF-pubsections.yaml
+++ b/llvm/test/ObjectYAML/MachO/DWARF-pubsections.yaml
@@ -356,7 +356,8 @@ DWARF:
## contents, if the "debug_pubnames"/"debug_pubtypes" entry doesn't exist in the
## "DWARF" entry.
-# RUN: yaml2obj --docnum=2 %s | obj2yaml | FileCheck %s --check-prefix=EMPTY
+# RUN: yaml2obj --docnum=2 %s -o %t2
+# RUN: obj2yaml %t2 | FileCheck %s --check-prefix=EMPTY
# EMPTY: Sections:
# EMPTY-NEXT: - sectname: __debug_pubnames
@@ -394,7 +395,7 @@ FileHeader:
cpusubtype: 0x00000003
filetype: 0x0000000A
ncmds: 1
- sizeofcmds: 1800
+ sizeofcmds: 1772
flags: 0x00000000
reserved: 0x00000000
LoadCommands:
More information about the llvm-commits
mailing list