OLD | NEW |
(Empty) | |
| 1 //===- lib/MC/MCNaCl.cpp - NaCl-specific MC implementation ----------------===// |
| 2 // |
| 3 // The LLVM Compiler Infrastructure |
| 4 // |
| 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. |
| 7 // |
| 8 //===----------------------------------------------------------------------===// |
| 9 |
| 10 #include "llvm/MC/MCNaCl.h" |
| 11 #include "llvm/ADT/Triple.h" |
| 12 #include "llvm/MC/MCContext.h" |
| 13 #include "llvm/MC/MCSectionELF.h" |
| 14 #include "llvm/MC/MCStreamer.h" |
| 15 #include "llvm/Support/ELF.h" |
| 16 |
| 17 static const char NoteNamespace[] = "NaCl"; |
| 18 |
| 19 namespace llvm { |
| 20 void initializeNaClMCStreamer(MCStreamer &Streamer, MCContext &Ctx, |
| 21 const Triple &TheTriple) { |
| 22 assert(TheTriple.isOSNaCl()); |
| 23 const char *NoteName; |
| 24 const char *NoteArch; |
| 25 unsigned BundleAlign; |
| 26 switch (TheTriple.getArch()) { |
| 27 case Triple::arm: |
| 28 NoteName = ".note.NaCl.ABI.arm"; |
| 29 NoteArch = "arm"; |
| 30 BundleAlign = 4; |
| 31 break; |
| 32 case Triple::mipsel: |
| 33 NoteName = ".note.NaCl.ABI.mipsel"; |
| 34 NoteArch = "mipsel"; |
| 35 BundleAlign = 4; |
| 36 break; |
| 37 case Triple::x86: |
| 38 NoteName = ".note.NaCl.ABI.x86-32"; |
| 39 NoteArch = "x86-32"; |
| 40 BundleAlign = 5; |
| 41 break; |
| 42 case Triple::x86_64: |
| 43 NoteName = ".note.NaCl.ABI.x86-64"; |
| 44 NoteArch = "x86-64"; |
| 45 BundleAlign = 5; |
| 46 break; |
| 47 default: |
| 48 report_fatal_error("Unsupported architecture for NaCl"); |
| 49 } |
| 50 |
| 51 // Set bundle-alignment as required by the NaCl ABI for the target. |
| 52 Streamer.EmitBundleAlignMode(BundleAlign); |
| 53 |
| 54 // Emit an ELF Note section in its own COMDAT group which identifies NaCl |
| 55 // object files to the gold linker, so it can use the NaCl layout. |
| 56 const MCSection *Note = Ctx.getELFSection( |
| 57 NoteName, ELF::SHT_NOTE, ELF::SHF_ALLOC | ELF::SHF_GROUP, |
| 58 SectionKind::getReadOnly(), 0, NoteName); |
| 59 |
| 60 // TODO(dschuff) This should probably use PushSection and PopSection, but |
| 61 // PopSection will assert if there haven't been any other sections switched to |
| 62 // yet. |
| 63 Streamer.SwitchSection(Note); |
| 64 Streamer.EmitIntValue(strlen(NoteNamespace) + 1, 4); |
| 65 Streamer.EmitIntValue(strlen(NoteArch) + 1, 4); |
| 66 Streamer.EmitIntValue(ELF::NT_VERSION, 4); |
| 67 Streamer.EmitBytes(NoteNamespace); |
| 68 Streamer.EmitIntValue(0, 1); // NUL terminator |
| 69 Streamer.EmitValueToAlignment(4); |
| 70 Streamer.EmitBytes(NoteArch); |
| 71 Streamer.EmitIntValue(0, 1); // NUL terminator |
| 72 Streamer.EmitValueToAlignment(4); |
| 73 } |
| 74 } // namespace llvm |
OLD | NEW |