Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(114)

Side by Side Diff: lib/MC/MCNaCl.cpp

Issue 15067009: LLVM: Add ELF Note section to NaCl object files identifying them as such to gold (Closed) Base URL: http://git.chromium.org/native_client/pnacl-llvm.git@master
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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";
Mark Seaborn 2013/05/10 19:52:46 static const char NoteNamespace[] = "NaCl"; That
Derek Schuff 2013/05/10 22:59:26 Done.
18
19 namespace llvm {
20 void initializeNaClMCStreamer(MCStreamer &Streamer, MCContext &Ctx,
21 const Triple &TheTriple) {
22 assert(TheTriple.isOSNaCl());
23 errs() << "initializeNaClMCStreamer\n";
Mark Seaborn 2013/05/10 19:52:46 Remove this debugging output
Derek Schuff 2013/05/10 22:59:26 Done.
24 const char *NoteName;
25 const char *NoteArch;
26 unsigned BundleAlign;
27 switch (TheTriple.getArch()) {
28 case Triple::arm:
29 NoteName = ".note.NaCl.ABI.arm";
30 NoteArch = "arm";
31 BundleAlign = 4;
32 break;
33 case Triple::mipsel:
34 NoteName = ".note.NaCl.ABI.mipsel";
35 NoteArch = "mipsel";
36 BundleAlign = 4;
37 break;
38 case Triple::x86:
39 NoteName = ".note.NaCl.ABI.x86-32";
40 NoteArch = "x86-32";
41 BundleAlign = 5;
42 break;
43 case Triple::x86_64:
44 NoteName = ".note.NaCl.ABI.x86-64";
45 NoteArch = "x86-64";
46 BundleAlign = 5;
47 break;
48 default:
49 report_fatal_error("Unsupported architecture for NaCl");
50 }
51
52 // Set bundle-alignment as required by the NaCl ABI for the target.
53 Streamer.EmitBundleAlignMode(BundleAlign);
54
55 // Emit an ELF Note section in its own COMDAT group which identifies NaCl
56 // object files to the gold linker, so it can use the NaCl layout.
57 const MCSection *Note = Ctx.getELFSection(
58 NoteName, ELF::SHT_NOTE, ELF::SHF_ALLOC | ELF::SHF_GROUP,
Mark Seaborn 2013/05/10 19:52:46 Nit: Indent by 4 rather than 6?
Derek Schuff 2013/05/10 22:59:26 Done.
59 SectionKind::getReadOnly(), 0, NoteName);
60
61 // TODO(dschuff) This should probably use PushSection and PopSection, but
62 // PopSection will assert if there haven't been any other sections switched to
63 // yet.
64 Streamer.SwitchSection(Note);
65 Streamer.EmitIntValue(strlen(NoteNamespace) + 1, 4);
66 Streamer.EmitIntValue(strlen(NoteArch) + 1, 4);
67 Streamer.EmitIntValue(1, 4); // NT_VERSION or maybe just our version number
68 Streamer.EmitValueToAlignment(4);
Mark Seaborn 2013/05/10 19:52:46 This one isn't needed, BTW.
Derek Schuff 2013/05/10 22:59:26 Done.
69 Streamer.EmitBytes(NoteNamespace);
70 Streamer.EmitIntValue(0, 1); // NUL terminator
71 Streamer.EmitValueToAlignment(4);
72 Streamer.EmitBytes(NoteArch);
73 Streamer.EmitIntValue(0, 1); // NUL terminator
74 Streamer.EmitValueToAlignment(4);
75 }
76 } // namespace llvm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698