[llvm-commits] [llvm] r68005 - in /llvm/trunk: include/llvm/Constant.h include/llvm/Target/TargetAsmInfo.h lib/Target/TargetAsmInfo.cpp
Anton Korobeynikov
asl at math.spbu.ru
Sun Mar 29 10:13:52 PDT 2009
Author: asl
Date: Sun Mar 29 12:13:49 2009
New Revision: 68005
URL: http://llvm.org/viewvc/llvm-project?rev=68005&view=rev
Log:
Honour relocation behaviour stuff for ro objects
Modified:
llvm/trunk/include/llvm/Constant.h
llvm/trunk/include/llvm/Target/TargetAsmInfo.h
llvm/trunk/lib/Target/TargetAsmInfo.cpp
Modified: llvm/trunk/include/llvm/Constant.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Constant.h?rev=68005&r1=68004&r2=68005&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Constant.h (original)
+++ llvm/trunk/include/llvm/Constant.h Sun Mar 29 12:13:49 2009
@@ -20,6 +20,7 @@
template<typename T> class SmallVectorImpl;
namespace Reloc {
+ const unsigned None = 0;
const unsigned Local = 1 << 0; ///< Local relocations are required
const unsigned Global = 1 << 1; ///< Global relocations are required
const unsigned LocalOrGlobal = Local | Global;
Modified: llvm/trunk/include/llvm/Target/TargetAsmInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetAsmInfo.h?rev=68005&r1=68004&r2=68005&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/TargetAsmInfo.h (original)
+++ llvm/trunk/include/llvm/Target/TargetAsmInfo.h Sun Mar 29 12:13:49 2009
@@ -577,6 +577,12 @@
virtual SectionKind::Kind
SectionKindForGlobal(const GlobalValue *GV) const;
+ /// RelocBehaviour - Describes how relocations should be treated when
+ /// selecting sections. Reloc::Global bit should be set if global
+ /// relocations should force object to be placed in read-write
+ /// sections. Reloc::Local bit should be set if local relocations should
+ /// force object to be placed in read-write sections.
+ virtual unsigned RelocBehaviour() const;
/// SectionFlagsForGlobal - This hook allows the target to select proper
/// section flags either for given global or for section.
Modified: llvm/trunk/lib/Target/TargetAsmInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/TargetAsmInfo.cpp?rev=68005&r1=68004&r2=68005&view=diff
==============================================================================
--- llvm/trunk/lib/Target/TargetAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/TargetAsmInfo.cpp Sun Mar 29 12:13:49 2009
@@ -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 @@
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 @@
// 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;
More information about the llvm-commits
mailing list