This is an archive of the discontinued LLVM Phabricator instance.

[yaml2obj][MachO] - Fix PubName/PubType handling.
ClosedPublic

Authored by grimar on Jun 11 2020, 1:26 PM.

Details

Summary

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.

I need this fix (in YAMLTraits.cpp) for D81655.

Diff Detail

Event Timeline

grimar created this revision.Jun 11 2020, 1:26 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 11 2020, 1:26 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
MaskRay accepted this revision.Jun 11 2020, 4:28 PM

Looks great!

This revision is now accepted and ready to land.Jun 11 2020, 4:28 PM
Higuoxing accepted this revision.Jun 11 2020, 6:19 PM

Thanks!

This revision was automatically updated to reflect the committed changes.