elf direct object emission

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

elf direct object emission

Reed Kotler
With the MIPS compiler, when we have static constants, in the .s file we
get something like:

     .type    $.str33,@object         # @.str33
     .section    .rodata.str1.1,"aMS",@progbits,1
$.str33:
     .asciz     "//"
     .size    $.str33, 3


Currently when we create direct object code we are referencing the
symbol as an offset in .rodata and not directly using the symbol with an
offset of 0.

It's useful for us when testing and debugging the direct object emitter
to end up with the same .o's essentially from the direct and not direct
object emitter paths , so that we can objdump and then diff them.

So I'm trying to figure out how to force $.str33 into the elf local
symbol table and then to reference it directly instead of the offset
from rodata. This is how gas ends up doing it from the .s file.

If anyone knows how to do this I'd appreciate knowing too.

Tia.

Reed

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: elf direct object emission

Jim Grosbach
Hi Reed,

I gather that symbols starting with '$' are normally assembler local labels (i.e., not output into the object file symbol table) for MIPS but that the system assembler keeps the symbols for string constants anyway?

If '$' isn't the prefix to indicate that symbols are assembler-local, that can be changed in lib/Target/Mips/MCTargetData/MipsMCAsmInfo.cpp via the PrivateGlobalPrefix value.

If '$' is correct, but there there need to be exceptions for symbols in some sections, that's done via MCAsmBackend::doesSectionRequireSymbols(). X86 on Darwin does this for strings, too, so that the linker can coalesce them and other such things. You can base the logic on pretty much anything about the section that's known to the MC layer. Typically it's section flags, but it can be via name matching or whatever else. If Mips wants the same ELF behavior that X86 does, you can probably just lift the code directly from ELFX86AsmBackend, which is:
  virtual bool doesSectionRequireSymbols(const MCSection &Section) const {
    const MCSectionELF &ES = static_cast<const MCSectionELF&>(Section);
    return ES.getFlags() & ELF::SHF_MERGE;
  }

-Jim

On Nov 29, 2011, at 8:21 PM, reed kotler wrote:

> With the MIPS compiler, when we have static constants, in the .s file we
> get something like:
>
>     .type    $.str33,@object         # @.str33
>     .section    .rodata.str1.1,"aMS",@progbits,1
> $.str33:
>     .asciz     "//"
>     .size    $.str33, 3
>
>
> Currently when we create direct object code we are referencing the
> symbol as an offset in .rodata and not directly using the symbol with an
> offset of 0.
>
> It's useful for us when testing and debugging the direct object emitter
> to end up with the same .o's essentially from the direct and not direct
> object emitter paths , so that we can objdump and then diff them.
>
> So I'm trying to figure out how to force $.str33 into the elf local
> symbol table and then to reference it directly instead of the offset
> from rodata. This is how gas ends up doing it from the .s file.
>
> If anyone knows how to do this I'd appreciate knowing too.
>
> Tia.
>
> Reed
>
> _______________________________________________
> LLVM Developers mailing list
> [hidden email]         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev