[llvm-dev] Help adding entries to .symtab

Robinson, Paul via llvm-dev llvm-dev at lists.llvm.org
Thu Dec 14 13:34:42 PST 2017


Hi Liad,
I'm not an expert in MC, but what you describe doesn't sound any different from how you would handle a branch instruction.  Create an MCSymbol that represents the address of the target instruction; use that symbol as an operand in the referencing instruction; emit the symbol as a label just prior to emitting the target instruction.  The second and third steps can occur in either order, depending on which instruction is emitted first.  I'd expect the reference to be fixed up as part of the normal assembly and linking process, nothing special there.
It's a little more complicated if the two instructions are in different compilation units, but if they are in the same compilation then it should be pretty straightforward.
--paulr

From: Liad Mordekoviz [mailto:liad.mordekoviz at nextsilicon.com]
Sent: Thursday, December 14, 2017 1:00 PM
To: Robinson, Paul; llvm-dev
Subject: Re: [llvm-dev] Help adding entries to .symtab

Hey Paul,
first of all thank you for taking the time to answer me,
if I understand you correctly, I need to modify the instruction it self so one of it's operands is a symbol, and then at MC layer handle that symbol and add an entry to the symtab for that label?
What kind of symbol should I use doing such thing? external symbol or MCSymbol?
I was trying to find where in the code during the MC layer I add entries to the symtab, I'd really appreciate some directions in the area.

Let me give an example so my questions might be a bit more clearer:
BB#0
...some opcodes...
mov r1, BB#1

BB#1
...some opcodes...

I'd like to put a place holder instead of the BB#1 in the mov opcode, and create a symbol named "BB#1" that points to that opcode, so during link time I can replace that placeholder with the actual address of BB#1.

Again thank you for your time and answer,
Liad.

On Thu, Dec 14, 2017 at 9:03 PM, Robinson, Paul <paul.robinson at sony.com<mailto:paul.robinson at sony.com>> wrote:
The .symtab has symbols; you could define a label for the instruction, and store something in the symbol table entry for the label.  This kind of thing would be done in the MC layer.
This would be one way to provide annotations that aren't needed for execution.  If you need to change the instruction itself, for example to have the instruction refer to memory somewhere, then you need to modify the instruction itself.
--paulr

From: llvm-dev [mailto:llvm-dev-bounces at lists.llvm.org<mailto:llvm-dev-bounces at lists.llvm.org>] On Behalf Of Liad Mordekoviz via llvm-dev
Sent: Thursday, December 14, 2017 2:37 AM
To: llvm-dev
Subject: [llvm-dev] Help adding entries to .symtab

Hi everyone,

I am fairly new to LLVM, I'm working on a new backend.
I am trying to add information to a specific instruction using the .symtab in the ELF format.
I've been searching through the LLVM source code trying to find a way to do such a thing.
Can anyone help me with some directions or point me to some documents in the matter.

Thanks, Liad.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20171214/e5be2313/attachment-0001.html>


More information about the llvm-dev mailing list