summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Target/TargetAsmInfo.cpp
diff options
context:
space:
mode:
authorAnton Korobeynikov <asl@math.spbu.ru>2009-03-29 17:13:49 +0000
committerAnton Korobeynikov <asl@math.spbu.ru>2009-03-29 17:13:49 +0000
commit088ebede5348a7b2f64a15f35f00c94bad5236aa (patch)
tree90d095578d91d3cadbae2d7ca86d756b8e434fc2 /llvm/lib/Target/TargetAsmInfo.cpp
parent7437b59caf36e995ae62a47490d5919dc9146548 (diff)
downloadbcm5719-llvm-088ebede5348a7b2f64a15f35f00c94bad5236aa.tar.gz
bcm5719-llvm-088ebede5348a7b2f64a15f35f00c94bad5236aa.zip
Honour relocation behaviour stuff for ro objects
llvm-svn: 68005
Diffstat (limited to 'llvm/lib/Target/TargetAsmInfo.cpp')
-rw-r--r--llvm/lib/Target/TargetAsmInfo.cpp25
1 files changed, 22 insertions, 3 deletions
diff --git a/llvm/lib/Target/TargetAsmInfo.cpp b/llvm/lib/Target/TargetAsmInfo.cpp
index 8f5941fb9e4..80f80003fe8 100644
--- a/llvm/lib/Target/TargetAsmInfo.cpp
+++ b/llvm/lib/Target/TargetAsmInfo.cpp
@@ -19,6 +19,7 @@
#include "llvm/Module.h"
#include "llvm/Type.h"
#include "llvm/Target/TargetAsmInfo.h"
+#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetOptions.h"
#include "llvm/Support/Dwarf.h"
#include <cctype>
@@ -189,6 +190,12 @@ static bool isConstantString(const Constant *C) {
return false;
}
+unsigned TargetAsmInfo::RelocBehaviour() const {
+ // By default - all relocations in PIC mode would force symbol to be
+ // placed in r/w section.
+ return (TM.getRelocationModel() != Reloc::Static ?
+ Reloc::LocalOrGlobal : Reloc::None);
+}
SectionKind::Kind
TargetAsmInfo::SectionKindForGlobal(const GlobalValue *GV) const {
@@ -208,9 +215,21 @@ TargetAsmInfo::SectionKindForGlobal(const GlobalValue *GV) const {
// check its initializer to decide, which section to output it into. Also
// note, there is no thread-local r/o section.
Constant *C = GVar->getInitializer();
- if (C->ContainsRelocations())
- return SectionKind::ROData;
- else {
+ if (C->ContainsRelocations(Reloc::LocalOrGlobal)) {
+ // Decide, whether it is still possible to put symbol into r/o section.
+ unsigned Reloc = RelocBehaviour();
+
+ // We already did a query for 'all' relocs, thus - early exits.
+ if (Reloc == Reloc::LocalOrGlobal)
+ return SectionKind::Data;
+ else if (Reloc == Reloc::None)
+ return SectionKind::ROData;
+ else {
+ // Ok, target wants something funny. Honour it.
+ return (C->ContainsRelocations(Reloc) ?
+ SectionKind::Data : SectionKind::ROData);
+ }
+ } else {
// Check, if initializer is a null-terminated string
if (isConstantString(C))
return SectionKind::RODataMergeStr;
OpenPOWER on IntegriCloud