Skip to content

[BOLT]How to add a Global Symbol in BOLT Pass #121322

@wuwen03

Description

@wuwen03

When writing a BOLT Pass, I have to add some data in data section and create a Symbol which references the data. Then I will use the Symbol to generate some MCInst. I code it as bellow:

        uint8_t *array = new uint8_t [1024];
        auto &Section = BC.registerOrUpdateSection("MyData", ELF::SHT_PROGBITS, BinarySection::getFlags(false,false,true),array,1024);
        array[0] = 1;//generate some data in the Section
        Section.setOutputAddress(/*I don't know*/);
        Section.setOutputFileOffset(/*"I don't know"*/);
        int SymbolAddress;/*I don't know*/
        BC.getOrCreateGlobalSymbol(SymbolAddress, "DATAAt",8);

However, the Symbol must be given a specific Address which is corresponding to the Section OutputAddress. However, the OutputAddress and OutputFileOffset is defined after all the BOLT PASSes, so I can't get the information inside my BOLT PASS, and I failed to define them by myself.
Is there any way to handle it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    BOLTquestionA question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions