zan jyu Wong
2015-Aug-04 02:03 UTC
[LLVMdev] 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150804/4225b180/attachment.html>
Tim Northover
2015-Aug-04 03:17 UTC
[LLVMdev] Help needed about code & data mixing when emit object files
Hi Huang, On 3 August 2015 at 19:03, zan jyu Wong <zyfwong at gmail.com> wrote:> 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): http://infocenter.arm.com/help/topic/com.arm.doc.ihi0044e/IHI0044E_aaelf.pdf. 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.
zan jyu Wong
2015-Aug-04 07:55 UTC
[LLVMdev] Help needed about code & data mixing when emit object files
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 On Tue, Aug 4, 2015 at 11:17 AM, Tim Northover <t.p.northover at gmail.com> wrote:> Hi Huang, > > On 3 August 2015 at 19:03, zan jyu Wong <zyfwong at gmail.com> wrote: > > 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): > > http://infocenter.arm.com/help/topic/com.arm.doc.ihi0044e/IHI0044E_aaelf.pdf > . > 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. >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150804/295c694c/attachment.html>