aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/llvm/Target/TargetAsmInfo.h7
-rw-r--r--include/llvm/Target/TargetOptions.h2
-rw-r--r--lib/Target/TargetAsmInfo.cpp1
-rw-r--r--lib/Target/TargetMachine.cpp6
-rwxr-xr-xlib/Target/X86/X86ATTAsmPrinter.cpp23
-rw-r--r--lib/Target/X86/X86AsmPrinter.cpp11
-rw-r--r--lib/Target/X86/X86Subtarget.cpp6
-rw-r--r--test/CodeGen/X86/test-pic-6.ll17
8 files changed, 57 insertions, 16 deletions
diff --git a/include/llvm/Target/TargetAsmInfo.h b/include/llvm/Target/TargetAsmInfo.h
index 6d80a7ebc8..1b957898f9 100644
--- a/include/llvm/Target/TargetAsmInfo.h
+++ b/include/llvm/Target/TargetAsmInfo.h
@@ -38,6 +38,10 @@ namespace llvm {
/// DataSection - Section directive for standard data.
///
const char *DataSection; // Defaults to ".data".
+
+ /// BSSSection - Section directive for uninitialized data.
+ ///
+ const char *BSSSection; // Default to ".bss".
/// AddressSize - Size of addresses used in file.
///
@@ -313,6 +317,9 @@ namespace llvm {
const char *getDataSection() const {
return DataSection;
}
+ const char *getBSSSection() const {
+ return BSSSection;
+ }
unsigned getAddressSize() const {
return AddressSize;
}
diff --git a/include/llvm/Target/TargetOptions.h b/include/llvm/Target/TargetOptions.h
index 4d21b0b060..89234de644 100644
--- a/include/llvm/Target/TargetOptions.h
+++ b/include/llvm/Target/TargetOptions.h
@@ -54,6 +54,8 @@ namespace llvm {
/// generate libcalls to the software floating point library instead of
/// target FP instructions.
extern bool UseSoftFloat;
+
+ extern bool NoZerosInBSS;
} // End llvm namespace
#endif
diff --git a/lib/Target/TargetAsmInfo.cpp b/lib/Target/TargetAsmInfo.cpp
index b184500744..b90eaa1668 100644
--- a/lib/Target/TargetAsmInfo.cpp
+++ b/lib/Target/TargetAsmInfo.cpp
@@ -19,6 +19,7 @@ using namespace llvm;
TargetAsmInfo::TargetAsmInfo() :
TextSection(".text"),
DataSection(".data"),
+ BSSSection(".bss"),
AddressSize(4),
NeedsSet(false),
MaxInstLength(4),
diff --git a/lib/Target/TargetMachine.cpp b/lib/Target/TargetMachine.cpp
index 7547614a71..f6b3fd09f0 100644
--- a/lib/Target/TargetMachine.cpp
+++ b/lib/Target/TargetMachine.cpp
@@ -28,6 +28,7 @@ namespace llvm {
bool UnsafeFPMath;
bool FiniteOnlyFPMathOption;
bool UseSoftFloat;
+ bool NoZerosInBSS;
Reloc::Model RelocationModel;
CodeModel::Model CMModel;
}
@@ -61,6 +62,11 @@ namespace {
cl::desc("Generate software floating point library calls"),
cl::location(UseSoftFloat),
cl::init(false));
+ cl::opt<bool, true>
+ DontPlaceZerosInBSS("nozero-initialized-in-bss",
+ cl::desc("Don't place zero-initialized symbols into bss section"),
+ cl::location(NoZerosInBSS),
+ cl::init(false));
cl::opt<llvm::Reloc::Model, true>
DefRelocationModel(
diff --git a/lib/Target/X86/X86ATTAsmPrinter.cpp b/lib/Target/X86/X86ATTAsmPrinter.cpp
index 02faf7cdb3..1dd53c7a02 100755
--- a/lib/Target/X86/X86ATTAsmPrinter.cpp
+++ b/lib/Target/X86/X86ATTAsmPrinter.cpp
@@ -323,22 +323,19 @@ void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
O << Offset;
if (isMemOp) {
- if (isExt) {
- if (Subtarget->isPICStyleGOT()) {
+ if (Subtarget->isPICStyleGOT()) {
+ if (Subtarget->GVRequiresExtraLoad(GV, TM, false))
O << "@GOT";
- } else if (Subtarget->isPICStyleRIPRel()) {
+ else
+ O << "@GOTOFF";
+ } else
+ if (isExt && Subtarget->isPICStyleRIPRel())
O << "@GOTPCREL(%rip)";
- } else if (Subtarget->is64Bit() && !NotRIPRel)
- // Use rip when possible to reduce code size, except when
- // index or base register are also part of the address. e.g.
- // foo(%rip)(%rcx,%rax,4) is not legal
- O << "(%rip)";
- } else {
- if (Subtarget->is64Bit() && !NotRIPRel)
+ else if (Subtarget->is64Bit() && !NotRIPRel)
+ // Use rip when possible to reduce code size, except when
+ // index or base register are also part of the address. e.g.
+ // foo(%rip)(%rcx,%rax,4) is not legal
O << "(%rip)";
- else if (Subtarget->isPICStyleGOT())
- O << "@GOTOFF";
- }
}
return;
diff --git a/lib/Target/X86/X86AsmPrinter.cpp b/lib/Target/X86/X86AsmPrinter.cpp
index 767ab23ce3..bea3914fe6 100644
--- a/lib/Target/X86/X86AsmPrinter.cpp
+++ b/lib/Target/X86/X86AsmPrinter.cpp
@@ -28,6 +28,7 @@
#include "llvm/Assembly/Writer.h"
#include "llvm/Support/Mangler.h"
#include "llvm/Target/TargetAsmInfo.h"
+#include "llvm/Target/TargetOptions.h"
using namespace llvm;
static X86FunctionInfo calculateFunctionInfo(const Function *F,
@@ -149,7 +150,10 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
O << "\t.zerofill __DATA__, __common, " << name << ", "
<< Size << ", " << Align;
} else {
- SwitchToDataSection(TAI->getDataSection(), I);
+ if (!NoZerosInBSS && TAI->getBSSSection())
+ SwitchToDataSection(TAI->getBSSSection(), I);
+ else
+ SwitchToDataSection(TAI->getDataSection(), I);
if (TAI->getLCOMMDirective() != NULL) {
if (I->hasInternalLinkage()) {
O << TAI->getLCOMMDirective() << name << "," << Size;
@@ -224,7 +228,10 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
SwitchToDataSection(SectionName.c_str());
} else {
- SwitchToDataSection(TAI->getDataSection(), I);
+ if (C->isNullValue() && !NoZerosInBSS && TAI->getBSSSection())
+ SwitchToDataSection(TAI->getBSSSection(), I);
+ else
+ SwitchToDataSection(TAI->getDataSection(), I);
}
break;
diff --git a/lib/Target/X86/X86Subtarget.cpp b/lib/Target/X86/X86Subtarget.cpp
index 5f2342ff4d..be5c64d6d3 100644
--- a/lib/Target/X86/X86Subtarget.cpp
+++ b/lib/Target/X86/X86Subtarget.cpp
@@ -36,10 +36,14 @@ bool X86Subtarget::GVRequiresExtraLoad(const GlobalValue* GV,
bool isDirectCall) const
{
if (TM.getRelocationModel() != Reloc::Static)
- if (isTargetDarwin() || isPICStyleGOT()) {
+ if (isTargetDarwin()) {
return (!isDirectCall &&
(GV->hasWeakLinkage() || GV->hasLinkOnceLinkage() ||
(GV->isExternal() && !GV->hasNotBeenReadFromBytecode())));
+ } else if (isPICStyleGOT()) {
+ // Extra load is needed for all non-statics.
+ return (!isDirectCall &&
+ (GV->isExternal() || !GV->hasInternalLinkage()));
} else if (isTargetCygMing() || isTargetWindows()) {
return (GV->hasDLLImportLinkage());
}
diff --git a/test/CodeGen/X86/test-pic-6.ll b/test/CodeGen/X86/test-pic-6.ll
new file mode 100644
index 0000000000..9f295319d1
--- /dev/null
+++ b/test/CodeGen/X86/test-pic-6.ll
@@ -0,0 +1,17 @@
+; RUN: llvm-as < %s | llc -mtriple=i686-pc-linux-gnu -relocation-model=pic &&
+; RUN: llvm-as < %s | llc -mtriple=i686-pc-linux-gnu -relocation-model=pic | grep _GLOBAL_OFFSET_TABLE_ &&
+; RUN: llvm-as < %s | llc -mtriple=i686-pc-linux-gnu -relocation-model=pic | grep piclabel | wc -l | grep 3 &&
+; RUN: llvm-as < %s | llc -mtriple=i686-pc-linux-gnu -relocation-model=pic | grep GOT | wc -l | grep 3
+
+%ptr = global i32* null
+%dst = global i32 0
+%src = global i32 0
+
+define void %foo() {
+entry:
+ store i32* %dst, i32** %ptr
+ %tmp.s = load i32* %src
+ store i32 %tmp.s, i32* %dst
+ ret void
+}
+