* Fix one more bug in PIC codegen: extra load is needed for *all*
non-statics.
* Introduce new option to output zero-initialized data to .bss section.
This can reduce size of binaries. Enable it by default for ELF &
Cygwin/Mingw targets. Probably, Darwin should be also added.
llvm-svn: 33299
diff --git a/llvm/lib/Target/X86/X86ATTAsmPrinter.cpp b/llvm/lib/Target/X86/X86ATTAsmPrinter.cpp
index 02faf7c..1dd53c7 100755
--- a/llvm/lib/Target/X86/X86ATTAsmPrinter.cpp
+++ b/llvm/lib/Target/X86/X86ATTAsmPrinter.cpp
@@ -323,22 +323,19 @@
O << Offset;
if (isMemOp) {
- if (isExt) {
- if (Subtarget->isPICStyleGOT()) {
+ if (Subtarget->isPICStyleGOT()) {
+ if (Subtarget->GVRequiresExtraLoad(GV, TM, false))
O << "@GOT";
- } else if (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)
- O << "(%rip)";
- else if (Subtarget->isPICStyleGOT())
+ 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)";
}
return;
diff --git a/llvm/lib/Target/X86/X86AsmPrinter.cpp b/llvm/lib/Target/X86/X86AsmPrinter.cpp
index 767ab23..bea3914 100644
--- a/llvm/lib/Target/X86/X86AsmPrinter.cpp
+++ b/llvm/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 @@
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 @@
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/llvm/lib/Target/X86/X86Subtarget.cpp b/llvm/lib/Target/X86/X86Subtarget.cpp
index 5f2342f..be5c64d 100644
--- a/llvm/lib/Target/X86/X86Subtarget.cpp
+++ b/llvm/lib/Target/X86/X86Subtarget.cpp
@@ -36,10 +36,14 @@
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());
}