[LLVMdev] Proposal for -filetype=obj full big endian support

Carter, Jack jcarter at mips.com
Mon Dec 19 17:17:58 PST 2011


Proposal for ELF text and data big endian support for direct object generation

Unless I am mistaken, currently big endian support in the MC layer for ELF
direct object generation is limited to ELF headers and tables like relocations.
Text and data section contents are still generated as individual bytes.
It looks as if the effort was started, but never completed.

The proposal is to extend the MCDataFragment class to include a container
of offset/size that one can traverse generating each element in the correct
endianess:

  // Pseudo code

for (iterator it = begin(), ie = end(); it != ie; ++it) {

     switch (it.getValueSize()) {
      default:
        assert(0 && "Invalid size!");
      case 1: OW->Write8 (uint8_t (it.getValue())); break;
      case 2: OW->Write16(uint16_t(it.getValue())); break;
      case 4: OW->Write32(uint32_t(it.getValue())); break;
      case 8: OW->Write64(uint64_t(it.getValue())); break;
      }
    }

Note: ObjectWriter has a set of endian correcting routines as use above.

The output routines like the snippet above would be in lib/MC/MCAssembler.cpp

There is an MCInstFragment, but it doesn't seem to be used. All text and data
seem to go through MCDataFragment.

The offset/size container would be filled at the
lib/Taget/<your target>/MCTargetDesc level. In <your targetMCCODEEmitter.cpp
for at least text. Some other source file for data.

It would be nice if someone could prove that the support is already there
and I don't have to do anything to get it, but if not, is the above
strawman reasonable? If so, I'll implement it and put it up for review.

Cheers,

Jack
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20111220/0285840a/attachment.html>


More information about the llvm-dev mailing list