This patch lets the bb_addr_map (renamed to __llvm_bb_addr_map) section use a special section type (SHT_LLVM_BB_ADDR_MAP) instead of SHT_PROGBITS. This would help parsers, dumpers and other tools to use the sh_type ELF field to identify this section rather than relying on string comparison on the section name.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
This patch lets the bb_addr_map (renamed to llvm_bb_addr_map) section use a special section type (SHT_LLVM_BB_ADDR_MAP) instead of SHT_PROGBITS. This would help linker and other tools to use the sh_type ELF field to identify this section rather than relying on string comparison on the section name.
This description implies that some special processing is needed in the linker. (As you can see, when llvm_call_graph_profile and llvm_dependent_libraries were proposed, they had clear patches on the linker side.)
llvm/test/MC/AsmParser/section_types.s | ||
---|---|---|
13 | @note is covered by other tests. Keeping just llvm specific section types here should be fine. |
Maybe pivot the statement to say "dumpers and other tools"? Dumpers will need to know the section type for simpler processing of the code, even if the linker has no special handling currently.
Thanks @MaskRay and @jhenderson.
Changed the description and the test according to your comments.
xray_instr_map and xray_fn_idx are also an LLVM specific section types but they do not get their own section types. They use a dedicated dumper (llvm-xray), instead of llvm-readobj.
If the eventual behavior is to let LLD interpret .bb_addr_map differently (like .deplibs and .llvm_sympart*) differently (not "Rules for Linking Unrecognized Sections" on http://www.sco.com/developers/gabi/latest/ch4.sheader.html), having a dedicated section type seems fine. Though, I'd really like to know whether auto-defined __start_bb_addr_map and __stop_bb_addr_map are needed. If yes, the section name should not start with a period. And I'd like to know how the section is differently interpreted. xray_instr_map and xray_fn_idx only use generic ELF features.
No, there are no plans to treat this section differently in LLD. However, we will have an external tool parsing this section. Also we don't need start and stop symbols.
I noticed that there are other LLVM sections which use __llvm_* as a prefix for their section name, instead of .llvm_* or .llvm.* (see e.g. __llvm_prf_cnts). What do you think about using that style for the name? It's not necessary, and it looks like we have a bit of inconsistency going on here, but it's something worth considering.
That's possible too, but just to verify, do we still want to add the new section type?
Personally, I think we should still have a new section type - the section has a well-defined structure, which in turn means it can be parsed and dumped. We shouldn't need to use section names to distinguish it from other sections to determine which section to parse or dump.
I am not sure it will be a good idea. The start/stop symbols of __llvm_prf_cnts is __start___llvm_prf_cnts and __stop___llvm_prf_cnts. The 3 _ look strange.
If the optimization eventually will be ported to Mach-O: strlen("__llvm_prf_cnts") <= 16 so the section name can be encoded in Mach-O. __llvm_bb_addr_map is not.
Right. We won't be using the __start and __stop symbols.
If the optimization eventually will be ported to Mach-O: strlen("__llvm_prf_cnts") <= 16 so the section name can be encoded in Mach-O. __llvm_bb_addr_map is not.
Good point. Actually this shows the importance of using the section type as opposed to the section name. If necessary, we can always change the section name since we make sure we never rely on the actual name.
I think you also need to update the documentation: llvm\docs\Extensions.rst (https://llvm.org/docs/Extensions.html)
llvm/test/MC/AsmParser/llvm_section_types.s | ||
---|---|---|
2 ↗ | (On Diff #296366) | Perhaps just i386-pc-linux, as there is nothing GNU specific here. |
3 ↗ | (On Diff #296366) | |
15 ↗ | (On Diff #296366) | Add an empty line to separate the code and checks? |
Thanks @grimar.
I added the entry in the Extensions doc. I am not sure if my formatting is correct. I appreciate if you could please take a look.
I am not an expert in this area too, but it looks consistent with the rest of the file, so I think it is fine.
To recheck myself I've used "Online Sphinx editor" (https://livesphinx.herokuapp.com/) and its output looks fine to me too.
I've inlined a comment about a single concern/nit I have though.
llvm/docs/Extensions.rst | ||
---|---|---|
411 ↗ | (On Diff #296838) | Does #### has some special meaning? If not, I'd just put '#', that is the way other comments |
Thanks everyone for the review. I'll go ahead and commit this and start working on D88717.
Please make sure to run clang-format on all the bits of code you've modified.