class GlobalValue;
class GlobalVariable;
class Type;
+ class Mangler;
struct DarwinTargetAsmInfo: public virtual TargetAsmInfo {
const Section* TextCoalSection;
virtual const Section* SelectSectionForGlobal(const GlobalValue *GV) const;
virtual std::string UniqueSectionForGlobal(const GlobalValue* GV,
SectionKind::Kind kind) const;
+ virtual bool emitUsedDirectiveFor(const GlobalValue *GV,
+ Mangler *Mang) const;
const Section* MergeableConstSection(const GlobalVariable *GV) const;
const Section* MergeableConstSection(const Type *Ty) const;
const Section* MergeableStringSection(const GlobalVariable *GV) const;
class CallInst;
class GlobalValue;
class Type;
+ class Mangler;
class Section {
friend class TargetAsmInfo;
/// have names in the .o file. This is often "." or "L".
const char *PrivateGlobalPrefix; // Defaults to "."
- /// LessPrivateGlobalPrefix - This prefix is used for some Objective C
- /// metadata symbols that should be passed through the assembler but be
- /// removed by the linker. This is "l" on Darwin.
+ /// LessPrivateGlobalPrefix - This prefix is used for symbols that should
+ /// be passed through the assembler but be removed by the linker. This
+ /// is "l" on Darwin, currently used for some ObjC metadata.
const char *LessPrivateGlobalPrefix; // Defaults to ""
/// JumpTableSpecialLabelPrefix - If not null, a extra (dead) label is
return false;
}
+ /// emitUsedDirectiveFor - This hook allows targets to selectively decide
+ /// not to emit the UsedDirective for some symbols in llvm.used.
+ virtual bool emitUsedDirectiveFor(const GlobalValue *GV,
+ Mangler *Mang) const {
+ return (GV!=0);
+ }
+
/// PreferredEHDataFormat - This hook allows the target to select data
/// format used for encoding pointers in exception handling data. Reason is
/// 0 for data, 1 for code labels, 2 for function pointers. Global is true
}
/// EmitLLVMUsedList - For targets that define a TAI::UsedDirective, mark each
-/// global in the specified llvm.used list as being used with this directive.
-/// Internally linked data beginning with the PrivateGlobalPrefix or the
-/// LessPrivateGlobalPrefix does not have the directive emitted (this
-/// occurs in ObjC metadata).
+/// global in the specified llvm.used list for which emitUsedDirectiveFor
+/// is true, as being used with this directive.
+
void AsmPrinter::EmitLLVMUsedList(Constant *List) {
const char *Directive = TAI->getUsedDirective();
for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i) {
const GlobalValue *GV = findGlobalValue(InitList->getOperand(i));
- if (GV) {
- if (GV->hasInternalLinkage() && !isa<Function>(GV) &&
- ((strlen(TAI->getPrivateGlobalPrefix()) != 0 &&
- Mang->getValueName(GV)
- .substr(0,strlen(TAI->getPrivateGlobalPrefix())) ==
- TAI->getPrivateGlobalPrefix()) ||
- (strlen(TAI->getLessPrivateGlobalPrefix()) != 0 &&
- Mang->getValueName(GV)
- .substr(0,strlen(TAI->getLessPrivateGlobalPrefix())) ==
- TAI->getLessPrivateGlobalPrefix())))
- continue;
+ if (TAI->emitUsedDirectiveFor(GV, Mang)) {
O << Directive;
EmitConstantValueOnly(InitList->getOperand(i));
O << '\n';
#include "llvm/Function.h"
#include "llvm/GlobalVariable.h"
#include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/Mangler.h"
#include "llvm/Target/DarwinTargetAsmInfo.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetData.h"
SectionFlags::Writeable);
}
+/// emitUsedDirectiveFor - On Darwin, internally linked data beginning with
+/// the PrivateGlobalPrefix or the LessPrivateGlobalPrefix does not have the
+/// directive emitted (this occurs in ObjC metadata).
+
+bool
+DarwinTargetAsmInfo::emitUsedDirectiveFor(const GlobalValue* GV,
+ Mangler *Mang) const {
+ if (GV==0)
+ return false;
+ if (GV->hasInternalLinkage() && !isa<Function>(GV) &&
+ ((strlen(getPrivateGlobalPrefix()) != 0 &&
+ Mang->getValueName(GV).substr(0,strlen(getPrivateGlobalPrefix())) ==
+ getPrivateGlobalPrefix()) ||
+ (strlen(getLessPrivateGlobalPrefix()) != 0 &&
+ Mang->getValueName(GV).substr(0,strlen(getLessPrivateGlobalPrefix())) ==
+ getLessPrivateGlobalPrefix())))
+ return false;
+ return true;
+}
+
const Section*
DarwinTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
SectionKind::Kind Kind = SectionKindForGlobal(GV);