[llvm] [SHT_LLVM_FUNC_MAP][ObjectYaml]Introduce function address map section and emit dynamic instruction count(ObjectYaml part) (PR #124332)

Rahman Lavaee via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 29 11:03:11 PST 2025


================
@@ -535,6 +535,27 @@ Example of BBAddrMap with PGO data:
    .uleb128  1000                         # BB_3 basic block frequency (only when enabled)
    .uleb128  0                            # BB_3 successors count (only enabled with branch probabilities)
 
+``SHT_LLVM_FUNC_MAP`` Section (function address map)
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+This section stores the mapping from the binary address of function to its
+related metadata features. It is used to emit function-level analysis data and
+can be enabled through ``--func-map`` option. The fields are encoded in the
+following format:
+
+#. A version number byte used for backward compatibility.
----------------
rlavaee wrote:

> However, I don't have a sensible answer for COMDAT sections and, more importantly perhaps, --gc-sections (or indeed linker section deduplication). You could have individual entries in separate sections, which are then discarded when their parent sections are, but I'm not sure whether you could guarantee that the header and tail sections remain in the right order relative to the entries. DWARF sections dodge this by (suboptimally) keeping the dead entries and having a "tombstone" value for the address of entries that are considered irrelevant.

I just verified this with a simple example with a weak function defined in two modules:
```
__attribute__((weak)) int my_weak_function(){
	std::cout << "Implementation 1" << std::endl;
	return 0;
}
```
Dwarf keeps separate entries for these functions, but sets `DW_AT_low_pc` to 0 for the one that is not chosen.

Also, as you mentioned, we end up with two headers, one for each module. Each header points to the next one.
0x00000000: Compile Unit: length = 0x000015d8, format = DWARF32, version = 0x0005, unit_type = DW_UT_compile, abbr_offset = 0x0000, addr_size = 0x08 (next unit at 0x000015dc)
0x000015dc: Compile Unit: length = 0x00001785, format = DWARF32, version = 0x0005, unit_type = DW_UT_compile, abbr_offset = 0x0215, addr_size = 0x08 (next unit at 0x00002d65)


https://github.com/llvm/llvm-project/pull/124332


More information about the llvm-commits mailing list