This is an archive of the discontinued LLVM Phabricator instance.

[DWARFLinker][NFC] Change interface of DWARFLinker to specify accel table kinds explicitly.
ClosedPublic

Authored by avl on Aug 22 2022, 5:40 AM.

Details

Summary

Currently, DWARFLinker receives kind of accel tables as predefined sets:

Apple,   ///< .apple_names, .apple_namespaces, .apple_types, .apple_objc.
Dwarf,   ///< DWARF v5 .debug_names.
Default, ///< Dwarf for DWARF5 or later, Apple otherwise.
Pub,     ///< .debug_pubnames, .debug_pubtypes

This patch removes implicit sets of tables(Default, Dwarf) and allows to ask for several sets:

Apple,     ///< .apple_names, .apple_namespaces, .apple_types, .apple_objc.
Pub,       ///< .debug_pubnames, .debug_pubtypes
DebugNames ///< .debug_names.

It allows seamlessness adding more accel tables in the future: .gdb_index, .debug_cu_index...
Doing things that way, DWARFLinker will be independent of consumers' requirements.
f.e. dsymutil and llvm-dwarfutil may have different variants for Default set
(so, instead of implementing these differencies inside DWARFLinker it could be
implemented in the corresponding module).

Diff Detail

Event Timeline

avl created this revision.Aug 22 2022, 5:40 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 22 2022, 5:40 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
avl requested review of this revision.Aug 22 2022, 5:40 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 22 2022, 5:40 AM
clayborg requested changes to this revision.Aug 22 2022, 2:37 PM

I am not sure this change makes sense as all of the Apple tables should be included if you have any, and likewise for .debug_pubnames and .debug_pubtypes: you want both or none.

llvm/include/llvm/DWARFLinker/DWARFLinker.h
34–37

All of these go together and you never want any of them unless you have all of them. I would keep these as "Apple" as a single entry.

38–39

I would keep these as "Pub", again, you never want just one of them, you either want both or none.

This revision now requires changes to proceed.Aug 22 2022, 2:37 PM
avl added a comment.Aug 23 2022, 1:30 AM

I am not sure this change makes sense as all of the Apple tables should be included if you have any, and likewise for .debug_pubnames and .debug_pubtypes: you want both or none.

My intention is to allow generation other index tables. f.e. we might want to generate .gdb_index and/or .debug_cu_index. In that case we need to have a way to specify not only "Apple" or "Debug" but additional tables.

Another thing is that "Default" can be defined differently for different tools. Thus it would be good if DWARFLinker would not have knowledge about dsymutil or llvm-dwarfutil specifics.

What about following classification:

enum class DwarfLinkerAccelTableKind : uint8_t {
  Apple,            ///< .apple_names, .apple_namespaces, .apple_types, .apple_objc.
  DWARFv4,   ///< .debug_pubnames, .debug_pubtypes
  DWARFv5    ///< DWARF v5 .debug_names.
};

or even:

enum class DwarfLinkerAccelTableKind : uint8_t {
  Apple,            ///< .apple_names, .apple_namespaces, .apple_types, .apple_objc.
  DWARF,       ///< .debug_pubnames, .debug_pubtypes for DWARFv4 or  .debug_names for DWARFv5
};

We will be able to extend it for other tables later:

enum class DwarfLinkerAccelTableKind : uint8_t {
  Apple,            ///< .apple_names, .apple_namespaces, .apple_types, .apple_objc.
  DWARF,       ///< .debug_pubnames, .debug_pubtypes for DWARFv4 or  .debug_names for DWARFv5
  GDB_index
};

?

I am not sure this change makes sense as all of the Apple tables should be included if you have any, and likewise for .debug_pubnames and .debug_pubtypes: you want both or none.

My intention is to allow generation other index tables. f.e. we might want to generate .gdb_index and/or .debug_cu_index. In that case we need to have a way to specify not only "Apple" or "Debug" but additional tables.

Another thing is that "Default" can be defined differently for different tools. Thus it would be good if DWARFLinker would not have knowledge about dsymutil or llvm-dwarfutil specifics.

What about following classification:

enum class DwarfLinkerAccelTableKind : uint8_t {
  Apple,            ///< .apple_names, .apple_namespaces, .apple_types, .apple_objc.
  DWARFv4,   ///< .debug_pubnames, .debug_pubtypes
  DWARFv5    ///< DWARF v5 .debug_names.
};

Anything like this is fine with me as long as the buckets enable all of the needed sections to be emitted. I like the DWARFv4 and DWARFv5 separation you did above best out of all of our different DwarfLinkerAccelTableKind definitions that you proposed.

avl updated this revision to Diff 455211.Aug 24 2022, 7:50 AM

addressed comments.

JDevlieghere added inline comments.Aug 24 2022, 9:40 AM
llvm/include/llvm/DWARFLinker/DWARFLinker.h
33–37

So now this removes "None" and "Default" and renames "Pub" to "DWARFv4"? I think this is more confusing than it was.

If it were me I'd say:

enum class DwarfLinkerAccelTableKind : uint8_t {
  Apple,
  DebugNames,  // or DWARFv5 or DWARF5
  Pub,

On Apple platforms we want to use Apple for DWARF <=4 and debug names for >= 5.

818

I would expect a value of 1 here.

llvm/lib/DWARFLinker/DWARFLinker.cpp
1821–1823

Unrelated formatting changes?

avl added inline comments.Aug 24 2022, 11:30 AM
llvm/include/llvm/DWARFLinker/DWARFLinker.h
33–37

ok.

818

ok.

llvm/lib/DWARFLinker/DWARFLinker.cpp
1821–1823

It is related. The new formatting happened because nesting level was changed.

avl updated this revision to Diff 455346.Aug 24 2022, 1:26 PM

addressed comments.

avl updated this revision to Diff 460477.Sep 15 2022, 12:15 PM

rebased.

avl added a comment.Sep 15 2022, 12:21 PM

Note: I kept current behavior in this patch(i.e. for the case DsymutilAccelTableKind::Default the type of accelerator table is auto-detected: use DebugNames for (AtLeastOneDwarfAccelTable && !AtLeastOneAppleAccelTable) case, use Apple otherwise). If we want this - https://reviews.llvm.org/D132371#inline-1276384 - "On Apple platforms we want to use Apple for DWARF <=4 and debug names for >= 5" - then I would update the patch accordingly.

avl added a comment.Sep 19 2022, 2:55 AM

ping.

My understanding is that concerns raised by @clayborg and @JDevlieghere are already addressed.

Sorry for the delay! Looks good to me. I think someone from Apple/dsymutil should do the final acceptance though to ensure it is ok for them.

avl edited the summary of this revision. (Show Details)Sep 21 2022, 3:35 AM
avl edited the summary of this revision. (Show Details)
JDevlieghere added inline comments.Oct 4 2022, 5:23 PM
llvm/tools/dsymutil/DwarfLinkerForBinary.cpp
756–761

The original logic I tried to implement was to prefer the Dwarf debug names for Dwarf 5 and alter, and the Apple variant for anything before that. Can we retain that logic?

avl updated this revision to Diff 479226.Dec 1 2022, 3:09 AM

Excuse me for the delay. Addressed comment: select accelerator table for the "Default" case based on the dwarf version.

This revision was not accepted when it landed; it landed in state Needs Review.Dec 4 2022, 2:17 AM
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.