[llvm-dev] storing MBB MCSymbol in custom section

K Jelesnianski via llvm-dev llvm-dev at lists.llvm.org
Mon Nov 27 17:28:04 PST 2017


Dear llvm-dev-list,

I have created my own custom section to be added at the end into a
binary upon compilation which contains address of all basic blocks. As
the final address of the basic block is not known until link time, I
collect the MCSymbol* Symbol Values per BB in a temp array and at the
in the custom section and emit it (emitSymbolValue) into my section
within EmitEndOfAsmFile()

I have found people looking at slightly different uses of the basic
block address but running into the same problem as me when compiling.
$clang calc_pi.c -o calc_pi
fatal error: error in backend: Undefined temporary symbol

However when only compiling (incompletely via -S),
e.g. $clang calc_pi.c -o calc_pi -S ,
it does compile with the expected outputs and the basic block labels
properly generated in my section. I get a file with proper labels

e.g.
__custom_section:
    .long   19
    .quad   .LBB0_0
    .long   1
    .quad   .LBB0_1
    .long   28
    .quad   .LBB0_2
    .long   3
... etc.

TLDR: compiles correctly, will not link successfully to make a binary
because the symbol of the basic block in the .text section doesn't
exist. How do I ensure the Basic Block Symbol does not get destroyed
until my section is read in as well during linking?

Followup Question: How do I ensure that after my section has been
fleshed out with addresses, that I may then destroy those symbol
values as intended.

I feel it has something to do with the liveness of the basic blocks
symbols however I do not know where they are "destroyed" to prevent
this from happening to allow my custom section containing the basic
block labels to also be "converted to addresses" as in its original
function scope.

Sincerely,

Chris


More information about the llvm-dev mailing list