<div dir="ltr">On Tue, Jan 29, 2013 at 6:24 PM, Jack Carter <span dir="ltr"><<a href="mailto:jcarter@mips.com" target="_blank" class="cremed">jcarter@mips.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: jacksprat<br>
Date: Tue Jan 29 20:24:33 2013<br>
New Revision: 173885<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=173885&view=rev" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-project?rev=173885&view=rev</a><br>
Log:<br>
This patch implements runtime ARM specific<br>
setting of ELF header e_flags.<br>
<br>
Contributer: Jack Carter<br>
<br>
<br>
Added:<br>
    llvm/trunk/test/MC/ARM/elf-eflags-eabi-cg.ll<br>
Modified:<br>
    llvm/trunk/include/llvm/Support/ELF.h<br>
    llvm/trunk/lib/Target/ARM/ARMAsmPrinter.cpp<br>
    llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp<br>
    llvm/trunk/test/MC/ARM/elf-eflags-eabi.s<br>
<br>
Modified: llvm/trunk/include/llvm/Support/ELF.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/ELF.h?rev=173885&r1=173884&r2=173885&view=diff" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/ELF.h?rev=173885&r1=173884&r2=173885&view=diff</a><br>

==============================================================================<br>
--- llvm/trunk/include/llvm/Support/ELF.h (original)<br>
+++ llvm/trunk/include/llvm/Support/ELF.h Tue Jan 29 20:24:33 2013<br>
@@ -495,7 +495,15 @@ enum {<br>
 };<br>
<br>
 // ARM Specific e_flags<br>
-enum { EF_ARM_EABIMASK = 0xFF000000U };<br>
+enum {<br>
+  EF_ARM_EABI_UNKNOWN =   0x00000000U,<br>
+  EF_ARM_EABI_VER1 =      0x01000000U,<br>
+  EF_ARM_EABI_VER2 =      0x02000000U,<br>
+  EF_ARM_EABI_VER3 =      0x03000000U,<br>
+  EF_ARM_EABI_VER4 =      0x04000000U,<br>
+  EF_ARM_EABI_VER5 =      0x05000000U,<br>
+  EF_ARM_EABIMASK =       0xFF000000U<br>
+};<br>
<br>
 // ELF Relocation types for ARM<br>
 // Meets 2.08 ABI Specs.<br>
<br>
Modified: llvm/trunk/lib/Target/ARM/ARMAsmPrinter.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMAsmPrinter.cpp?rev=173885&r1=173884&r2=173885&view=diff" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMAsmPrinter.cpp?rev=173885&r1=173884&r2=173885&view=diff</a><br>

==============================================================================<br>
--- llvm/trunk/lib/Target/ARM/ARMAsmPrinter.cpp (original)<br>
+++ llvm/trunk/lib/Target/ARM/ARMAsmPrinter.cpp Tue Jan 29 20:24:33 2013<br>
@@ -37,6 +37,7 @@<br>
 #include "llvm/MC/MCAsmInfo.h"<br>
 #include "llvm/MC/MCAssembler.h"<br>
 #include "llvm/MC/MCContext.h"<br>
+#include "llvm/MC/MCELFStreamer.h"<br>
 #include "llvm/MC/MCInst.h"<br>
 #include "llvm/MC/MCInstBuilder.h"<br>
 #include "llvm/MC/MCObjectStreamer.h"<br>
@@ -45,6 +46,7 @@<br>
 #include "llvm/MC/MCSymbol.h"<br>
 #include "llvm/Support/CommandLine.h"<br>
 #include "llvm/Support/Debug.h"<br>
+#include "llvm/Support/ELF.h"<br>
 #include "llvm/Support/ErrorHandling.h"<br>
 #include "llvm/Support/TargetRegistry.h"<br>
 #include "llvm/Support/raw_ostream.h"<br>
@@ -699,6 +701,15 @@ void ARMAsmPrinter::EmitEndOfAsmFile(Mod<br>
     // generates code that does this, it is always safe to set.<br>
     OutStreamer.EmitAssemblerFlag(MCAF_SubsectionsViaSymbols);<br>
   }<br>
+  // FIXME: This should eventually end up somewhere else where more<br>
+  // intelligent flag decisions can be made. For now we are just maintaining<br>
+  // the status quo for ARM and setting EF_ARM_EABI_VER5 as the default.<br>
+  if (Subtarget->isTargetELF()) {<br>
+    if (OutStreamer.hasRawTextSupport()) return;<br>
+<br>
+    MCELFStreamer &MES = static_cast<MCELFStreamer &>(OutStreamer);<br>
+    MES.getAssembler().setELFHeaderEFlags(ELF::EF_ARM_EABI_VER5);<br>
+  }<br>
 }<br>
<br>
 //===----------------------------------------------------------------------===//<br>
<br>
Modified: llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp?rev=173885&r1=173884&r2=173885&view=diff" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp?rev=173885&r1=173884&r2=173885&view=diff</a><br>

==============================================================================<br>
--- llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp (original)<br>
+++ llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp Tue Jan 29 20:24:33 2013<br>
@@ -18,7 +18,9 @@<br>
 #include "llvm/ADT/StringSwitch.h"<br>
 #include "llvm/ADT/Twine.h"<br>
 #include "llvm/MC/MCAsmInfo.h"<br>
+#include "llvm/MC/MCAssembler.h"<br>
 #include "llvm/MC/MCContext.h"<br>
+#include "llvm/MC/MCELFStreamer.h"<br>
 #include "llvm/MC/MCExpr.h"<br>
 #include "llvm/MC/MCInst.h"<br>
 #include "llvm/MC/MCInstrDesc.h"<br>
@@ -28,6 +30,7 @@<br>
 #include "llvm/MC/MCRegisterInfo.h"<br>
 #include "llvm/MC/MCStreamer.h"<br>
 #include "llvm/MC/MCSubtargetInfo.h"<br>
+#include "llvm/Support/ELF.h"<br>
 #include "llvm/Support/MathExtras.h"<br>
 #include "llvm/Support/SourceMgr.h"<br>
 #include "llvm/Support/TargetRegistry.h"<br>
@@ -250,6 +253,13 @@ public:<br>
<br>
     // Not in an ITBlock to start with.<br>
     ITState.CurPosition = ~0U;<br>
+<br>
+    // Set ELF header flags.<br>
+    // FIXME: This should eventually end up somewhere else where more<br>
+    // intelligent flag decisions can be made. For now we are just maintaining<br>
+    // the status quo for ARM and setting EF_ARM_EABI_VER5 as the default.<br>
+    MCELFStreamer &MES = static_cast<MCELFStreamer &>(Parser.getStreamer());<br>
+    MES.getAssembler().setELFHeaderEFlags(ELF::EF_ARM_EABI_VER5);<br></blockquote><div><br></div><div style>Here, you don't test or check anything, you simply cast to MCELFStreamer, and run. This caused *really* strange bugs. I've fixed it in r174118 to use a proper check on the type of the MCStreamer here, but I would encourage you to audit some of the other changes in this area to make sure there aren't other instances of this bug.</div>
<div style><br></div><div style>In general, any use of static_cast<> to move through a dynamic class hierarchy in LLVM is pretty suspect, and something to investigate as there is usually a better pattern to follow.</div>
<div style><br></div><div style>-Chandler</div></div></div></div>