[llvm-commits] [llvm] r172837 - in /llvm/trunk: docs/LangRef.rst lib/CodeGen/TargetLoweringObjectFileImpl.cpp lib/MC/MCAsmStreamer.cpp test/MC/MachO/linker-options.ll
Daniel Dunbar
daniel at zuster.org
Fri Jan 18 11:37:00 PST 2013
Author: ddunbar
Date: Fri Jan 18 13:37:00 2013
New Revision: 172837
URL: http://llvm.org/viewvc/llvm-project?rev=172837&view=rev
Log:
[MC/Mach-O] Implement integrated assembler support for linker options.
- Also, fixup syntax errors in LangRef and missing newline in the MCAsmStreamer.
Added:
llvm/trunk/test/MC/MachO/linker-options.ll
Modified:
llvm/trunk/docs/LangRef.rst
llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
llvm/trunk/lib/MC/MCAsmStreamer.cpp
Modified: llvm/trunk/docs/LangRef.rst
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/LangRef.rst?rev=172837&r1=172836&r2=172837&view=diff
==============================================================================
--- llvm/trunk/docs/LangRef.rst (original)
+++ llvm/trunk/docs/LangRef.rst Fri Jan 18 13:37:00 2013
@@ -2628,10 +2628,10 @@
linker options, presumably to link against ``libz`` and the ``Cocoa``
framework::
- !0 = metadata !{ i32 6, "Linker Options",
+ !0 = metadata !{ i32 6, metadata !"Linker Options",
metadata !{
- !metadata { metadata !"-lz" },
- !metadata { metadata !"-framework", metadata !"Cocoa" } } }
+ metadata !{ metadata !"-lz" },
+ metadata !{ metadata !"-framework", metadata !"Cocoa" } } }
!llvm.module.flags = !{ !0 }
The metadata encoding as lists of lists of options, as opposed to a collapsed
Modified: llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp?rev=172837&r1=172836&r2=172837&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp (original)
+++ llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp Fri Jan 18 13:37:00 2013
@@ -406,14 +406,14 @@
// MachO
//===----------------------------------------------------------------------===//
-/// emitModuleFlags - Emit the module flags that specify the garbage collection
-/// information.
+/// emitModuleFlags - Perform code emission for module flags.
void TargetLoweringObjectFileMachO::
emitModuleFlags(MCStreamer &Streamer,
ArrayRef<Module::ModuleFlagEntry> ModuleFlags,
Mangler *Mang, const TargetMachine &TM) const {
unsigned VersionVal = 0;
unsigned ImageInfoFlags = 0;
+ MDNode *LinkerOptions = 0;
StringRef SectionVal;
for (ArrayRef<Module::ModuleFlagEntry>::iterator
@@ -427,14 +427,33 @@
StringRef Key = MFE.Key->getString();
Value *Val = MFE.Val;
- if (Key == "Objective-C Image Info Version")
+ if (Key == "Objective-C Image Info Version") {
VersionVal = cast<ConstantInt>(Val)->getZExtValue();
- else if (Key == "Objective-C Garbage Collection" ||
- Key == "Objective-C GC Only" ||
- Key == "Objective-C Is Simulated")
+ } else if (Key == "Objective-C Garbage Collection" ||
+ Key == "Objective-C GC Only" ||
+ Key == "Objective-C Is Simulated") {
ImageInfoFlags |= cast<ConstantInt>(Val)->getZExtValue();
- else if (Key == "Objective-C Image Info Section")
+ } else if (Key == "Objective-C Image Info Section") {
SectionVal = cast<MDString>(Val)->getString();
+ } else if (Key == "Linker Options") {
+ LinkerOptions = cast<MDNode>(Val);
+ }
+ }
+
+ // Emit the linker options if present.
+ if (LinkerOptions) {
+ for (unsigned i = 0, e = LinkerOptions->getNumOperands(); i != e; ++i) {
+ MDNode *MDOptions = cast<MDNode>(LinkerOptions->getOperand(i));
+ SmallVector<std::string, 4> StrOptions;
+
+ // Convert to strings.
+ for (unsigned ii = 0, ie = MDOptions->getNumOperands(); ii != ie; ++ii) {
+ MDString *MDOption = cast<MDString>(MDOptions->getOperand(ii));
+ StrOptions.push_back(MDOption->getString());
+ }
+
+ Streamer.EmitLinkerOptions(StrOptions);
+ }
}
// The section is mandatory. If we don't have it, then we don't have GC info.
Modified: llvm/trunk/lib/MC/MCAsmStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmStreamer.cpp?rev=172837&r1=172836&r2=172837&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAsmStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCAsmStreamer.cpp Fri Jan 18 13:37:00 2013
@@ -383,6 +383,7 @@
ie = Options.end(); it != ie; ++it) {
OS << ", " << '"' << *it << '"';
}
+ OS << "\n";
}
void MCAsmStreamer::EmitDataRegion(MCDataRegionType Kind) {
Added: llvm/trunk/test/MC/MachO/linker-options.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/MachO/linker-options.ll?rev=172837&view=auto
==============================================================================
--- llvm/trunk/test/MC/MachO/linker-options.ll (added)
+++ llvm/trunk/test/MC/MachO/linker-options.ll Fri Jan 18 13:37:00 2013
@@ -0,0 +1,35 @@
+; RUN: llc -O0 -mtriple=x86_64-apple-darwin -o - %s > %t
+; RUN: FileCheck --check-prefix=CHECK-ASM < %t %s
+
+; CHECK-ASM: .linker_option "-lz"
+; CHECK-ASM-NEXT: .linker_option "-framework", "Cocoa"
+
+; RUN: llc -O0 -mtriple=x86_64-apple-darwin -filetype=obj -o - %s | macho-dump > %t
+; RUN: FileCheck --check-prefix=CHECK-OBJ < %t %s
+
+; CHECK-OBJ: ('load_commands', [
+; CHECK-OBJ: # Load Command 1
+; CHECK-OBJ: (('command', 45)
+; CHECK-OBJ: ('size', 16)
+; CHECK-OBJ: ('count', 1)
+; CHECK-OBJ: ('_strings', [
+; CHECK-OBJ: "-lz",
+; CHECK-OBJ: ])
+; CHECK-OBJ: ),
+; CHECK-OBJ: # Load Command 2
+; CHECK-OBJ: (('command', 45)
+; CHECK-OBJ: ('size', 32)
+; CHECK-OBJ: ('count', 2)
+; CHECK-OBJ: ('_strings', [
+; CHECK-OBJ: "-framework",
+; CHECK-OBJ: "Cocoa",
+; CHECK-OBJ: ])
+; CHECK-OBJ: ),
+; CHECK-OBJ: ])
+
+!0 = metadata !{ i32 6, metadata !"Linker Options",
+ metadata !{
+ metadata !{ metadata !"-lz" },
+ metadata !{ metadata !"-framework", metadata !"Cocoa" } } }
+
+!llvm.module.flags = !{ !0 }
More information about the llvm-commits
mailing list