<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/121322>121322</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[BOLT]How to add a Global Symbol in BOLT Pass
</td>
</tr>
<tr>
<th>Labels</th>
<td>
BOLT
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
wuwen03
</td>
</tr>
</table>
<pre>
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 definite 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?
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJxsVF2vozYQ_TXmZbQIDCTcBx5I0uyNtKusmlR9XJl4ALfGjmwTxL-vbMjejy6K5Mgz58yZLzNrRacQK1LsSHGI2Oh6bappnFAlWdRoPld_96hgMsIJ1QGD3fnbFX4wawndwwl69kBwGhjnYPWAwJljINRyWrw5oRUwxeFmkDkEBpd5aLSEqRe3Hgy2aFDd0ILrF3QMVx_yBJOQEkaLwbKinIYOFRpPFeJ935-UdTGc4KY5gnDALDQopZ5IVpOkJptk_SU1rN8olCt_OiC0ZsawGUh2AIXTm6HYpQnNSXEg2e4dkI1OA6Gby5qYx-32scFOWIfmbP66c-ZwNRNaEkq_zwfmGKHUV-yPb0cvK6svr9efP_48f92drhdv2AnFzPwEBpcO3VGyzhJatkxaJHT_PJ0ZkdAXQvdBP6H7IJe-rHKX22KXkOIQRKbeQI-EHj-W79muUOI1eFI__8YW3Xl099HVnBv0TS8DS30C7vPbOvhX6YnQOlw_w_8PfhQSz21r0f1iIJR-JqGfedZPKLf2_yljTeb3MpLa96RDdzb7MHRfpW6YXBgILT9S0T0QSg_1ta7d0qTyl4D3s_OqJ3yg8f7v5nEYrYMGoRMPVMCAYyuUcAgr_TrmwsJNG4P2rhX3i-T0-5LDhyLH8CnWB2tYps9V9QFCaOTAWocGmJQBu-xrfblgSNVqvylsqVmHLvgI1WozsKBEKCs4wjC_IT3OBz1By4RE7sUvwTx6gGaGYbYo25gk9SksskFgaoaJzd65Z4pLv5skO0a8yvhL9sIirNJtVhT5dlNmUV_lLW6LnL_whG2KdttsNyUmLN1s03bTYpFEoqIJzVOaJUmZ5XkWb255xtNN2pY5LZOGkjzBgQkZS_kYYm26SFg7YpXSNKM0kqxBacNTR6lPzne7OESm8v5fmrGzJE-ksM6-MTjhZHgeA6A4vOrp-dwxWObqOQpCvT2O0Whk1Tt3t36Vl70Trh-b-KYHQo-efz2-3I3-B2-O0GOQawk9roofFf0vAAD__xNLyNg">