BBAddrMap provides metadata for basic block addresses and properties. It’s useful for post link optimization. The format of BBAddrMap is platform independent. We want to extend it to COFF so that Windows can also leverage it to apply post link optimization.
Current Limitations
The existing implementation has ELF-specific assumptions:
- Type definitions in
ELFTypes.hcoupled to ELF - Encoding/decoding logic mixed with ELF-specific code in
ELF.cpp - Section emission only for ELF targets
- Tool support (llvm-readobj, llvm-objdump) only handles ELF
To extend it to COFF. We want to refactor some code.
Proposed Changes
1. Refactor for Multi-Format Support
- Move
BBAddrMapandPGOAnalysisMaptypes fromELFTypes.hto new shared headerObject/BBAddrMap.h - Extract format-agnostic encoding/decoding to
Object/BBAddrMap.cpp - Keep format-specific operations (decompression, relocations) in format-specific files
2. Enable COFF Support
Driver & MC Layer:
- Remove ELF-only restriction in Clang driver
- Support
.llvm_bb_addr_mapCOFF sections
Object Library & Tools:
- Implement
COFFObjectFile::readBBAddrMap()for decoding - Handle COFF relocation types (IMAGE_REL_AMD64_ADDR64, IMAGE_REL_I386_DIR32, etc.)
- Extend llvm-readobj and llvm-objdump for COFF BBAddrMap
- Refactor common dumping logic into
ObjDumper