Help needed about code & data mixing when emit object files

Hi,
I’m building a new backend which can only load very limited range of imm. So I decided to use constant pool, and place constant pool entries close enough to instructions use the entries (we have very limited range PC-relative memory load). However, lld & llc output the object files that gather all constant pool entries into one section. How can I make them mix these entries into code section ?
By the way, I have read the ARM backend, and know how it place CONSTPOOL_ENTRY in basic block islands. However, I could not understand how to make it when emitting obj file. And when the code & data are mixed, the disassembler will failed to parse the binary properly. For example, if we place a CONSTPOOL_ENTRY in .text section and it will confused the disassembler. I wonder if is possible to emit subsections (of .text section) in *MCCodeEmitter to mix data into code and avoid confusing disassembler, like this [1]?
Any Ideas? Thanks.

[1] http://lists.cs.uiuc.edu/pipermail/llvmdev/2010-June/032263.html

Cheers.
Huang

Hi Huang,

By the way, I have read the ARM backend, and know how it place
CONSTPOOL_ENTRY in basic block islands.

You've basically found the way out. ARMConstantIslands is the
prototypical solution, and it's not pretty (to the extent that, even
though AArch64 would support something similar as a possible
optimisation, we've not implemented it due to the maintenance burden).

However, I could not understand how to make it when emitting obj file.

Not sure I follow. If you end up calling the appropriate EmitInt32 (or
whatever) methods on the MCStreamer it should work for both assembly
and object files.

And when the code & data are mixed, the
disassembler will failed to parse the binary properly.

If you want to support disassembly reliably, you need to enhance your
object format to describe where these constant islands are. On ARM,
both MachO and ELF came to the same conclusion (though implemented it
differently).

You might want to borrow from the ARM ELF ABI (since it looks like
you're targeting ELF):
Documentation – Arm Developer.
Search for "mapping symbols".

For example, if we
place a CONSTPOOL_ENTRY in .text section and it will confused the
disassembler. I wonder if is possible to emit subsections (of .text section)
in *MCCodeEmitter to mix data into code and avoid confusing disassembler,
like this [1]?

I've not heard of subsections in ELF. Maybe you could come up with a
scheme that would work, but I think it would be difficult.

Cheers.

Tim.

Hi Tim,

Thanks for your helping.

Not sure I follow. If you end up calling the appropriate EmitInt32 (or
whatever) methods on the MCStreamer it should work for both assembly
and object files.

I think I have misunderstood how *AsmPrinter works, is it not just `print’
assembly files, but also emit object files ?

If you want to support disassembly reliably, you need to enhance your
object format to describe where these constant islands are. On ARM,
both MachO and ELF came to the same conclusion (though implemented it
differently).
You might want to borrow from the ARM ELF ABI (since it looks like
you’re targeting ELF):
http://infocenter.arm.com/help/topic/com.arm.doc.ihi0044e/IHI0044E_aaelf.pdf.
Search for “mapping symbols”.

Sounds great, I’ll check it out.

Cheers.
Huang