llvm.org GIT mirror llvm / 8c6ed05
Big change #1 for personality function references: Eliminate the PersonalityPrefix/Suffix & NeedsIndirectEncoding fields from MAI: they aren't part of the asm syntax, they are related to the structure of the object file. To replace their functionality, add a new TLOF::getSymbolForDwarfGlobalReference method which asks targets to decide how to reference a global from EH in a pc-relative way. The default implementation just returns the symbol. The default darwin implementation references the symbol through an indirect $non_lazy_ptr stub. The bizarro x86-64 darwin specialization handles the weird "foo@GOTPCREL+4" hack. DwarfException.cpp now uses this to emit the reference to the symbol in the right way, and this also eliminates another horrible hack from DwarfException.cpp: - if (strcmp(MAI->getPersonalitySuffix(), "+4@GOTPCREL")) - O << "-" << MAI->getPCSymbol(); git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@81991 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 11 years ago
11 changed file(s) with 172 addition(s) and 56 deletion(s). Raw diff Collapse all Expand all
8383 /// is "l" on Darwin, currently used for some ObjC metadata.
8484 const char *LinkerPrivateGlobalPrefix; // Defaults to ""
8585
86 /// PersonalityPrefix/Suffix - If these are nonempty, these strings will
87 /// enclose any personality function in the common frame section.
88 ///
89 const char *PersonalityPrefix; // Defaults to ""
90 const char *PersonalitySuffix; // Defaults to ""
91
92 /// NeedsIndirectEncoding - If set, we need to set the indirect encoding bit
93 /// for EH in Dwarf.
94 ///
95 bool NeedsIndirectEncoding; // Defaults to false
96
9786 /// InlineAsmStart/End - If these are nonempty, they contain a directive to
9887 /// emit before and after an inline assembly statement.
9988 const char *InlineAsmStart; // Defaults to "#APP\n"
352341 const char *getLinkerPrivateGlobalPrefix() const {
353342 return LinkerPrivateGlobalPrefix;
354343 }
355 const char *getPersonalityPrefix() const {
356 return PersonalityPrefix;
357 }
358 const char *getPersonalitySuffix() const {
359 return PersonalitySuffix;
360 }
361 bool getNeedsIndirectEncoding() const {
362 return NeedsIndirectEncoding;
363 }
364344 const char *getInlineAsmStart() const {
365345 return InlineAsmStart;
366346 }
2525 class StringRef;
2626 class TargetMachine;
2727 class MCAsmInfo;
28 class MCExpr;
2829
2930 class TargetLoweringObjectFile {
3031 MCContext *Ctx;
172173 return 0;
173174 }
174175
176 /// getSymbolForDwarfGlobalReference - Return an MCExpr to use for a
177 /// pc-relative reference to the specified global variable from exception
178 /// handling information. In addition to the symbol, this returns
179 /// by-reference:
180 ///
181 /// IsIndirect - True if the returned symbol is actually a stub that contains
182 /// the address of the symbol, false if the symbol is the global itself.
183 ///
184 /// IsPCRel - True if the symbol reference is already pc-relative, false if
185 /// the caller needs to subtract off the address of the reference from the
186 /// symbol.
187 ///
188 virtual const MCExpr *
189 getSymbolForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang,
190 bool &IsIndirect, bool &IsPCRel) const;
191
175192 protected:
176193 virtual const MCSection *
177194 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
297314 const MCSection *getNonLazySymbolPointerSection() const {
298315 return NonLazySymbolPointerSection;
299316 }
317
318 /// getSymbolForDwarfGlobalReference - The mach-o version of this method
319 /// defaults to returning a stub reference.
320 virtual const MCExpr *
321 getSymbolForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang,
322 bool &IsIndirect, bool &IsPCRel) const;
300323 };
301324
302325
1616 #include "llvm/CodeGen/MachineFrameInfo.h"
1717 #include "llvm/CodeGen/MachineFunction.h"
1818 #include "llvm/CodeGen/MachineLocation.h"
19 #include "llvm/MC/MCAsmInfo.h"
20 #include "llvm/MC/MCContext.h"
21 #include "llvm/MC/MCExpr.h"
1922 #include "llvm/MC/MCSection.h"
2023 #include "llvm/MC/MCStreamer.h"
21 #include "llvm/MC/MCAsmInfo.h"
2224 #include "llvm/Target/TargetData.h"
2325 #include "llvm/Target/TargetFrameInfo.h"
2426 #include "llvm/Target/TargetLoweringObjectFile.h"
7476 /// EmitCIE - Emit a Common Information Entry (CIE). This holds information that
7577 /// is shared among many Frame Description Entries. There is at least one CIE
7678 /// in every non-empty .debug_frame section.
77 void DwarfException::EmitCIE(const Function *Personality, unsigned Index) {
79 void DwarfException::EmitCIE(const Function *PersonalityFn, unsigned Index) {
7880 // Size and sign of stack growth.
7981 int stackGrowth =
8082 Asm->TM.getFrameInfo()->getStackGrowthDirection() ==
8183 TargetFrameInfo::StackGrowsUp ?
8284 TD->getPointerSize() : -TD->getPointerSize();
8385
86 const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering();
87
8488 // Begin eh frame section.
85 Asm->OutStreamer.SwitchSection(Asm->getObjFileLowering().getEHFrameSection());
89 Asm->OutStreamer.SwitchSection(TLOF.getEHFrameSection());
8690
8791 if (MAI->is_EHSymbolPrivate())
8892 O << MAI->getPrivateGlobalPrefix();
89
9093 O << "EH_frame" << Index << ":\n";
94
9195 EmitLabel("section_eh_frame", Index);
9296
9397 // Define base labels.
106110 Asm->EOL("CIE Version");
107111
108112 // The personality presence indicates that language specific information will
109 // show up in the eh frame.
110
111 // FIXME: Don't hardcode these encodings.
113 // show up in the eh frame. Find out how we are supposed to lower the
114 // personality function reference:
115 const MCExpr *PersonalityRef = 0;
116 bool IsPersonalityIndirect = false, IsPersonalityPCRel = false;
117 if (PersonalityFn) {
118 // FIXME: HANDLE STATIC CODEGEN MODEL HERE.
119
120 // In non-static mode, ask the object file how to represent this reference.
121 PersonalityRef =
122 TLOF.getSymbolForDwarfGlobalReference(PersonalityFn, Asm->Mang,
123 IsPersonalityIndirect,
124 IsPersonalityPCRel);
125 }
126
112127 unsigned PerEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
113 if (Personality && MAI->getNeedsIndirectEncoding())
128 if (IsPersonalityIndirect)
114129 PerEncoding |= dwarf::DW_EH_PE_indirect;
115130 unsigned LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
116131 unsigned FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
119134 unsigned AugmentationSize = 0;
120135 char *APtr = Augmentation + 1;
121136
122 if (Personality) {
137 if (PersonalityRef) {
123138 // There is a personality function.
124139 *APtr++ = 'P';
125140 AugmentationSize += 1 + SizeOfEncodedValue(PerEncoding);
158173 Asm->EOL("Personality", PerEncoding);
159174
160175 // If there is a personality, we need to indicate the function's location.
161 if (Personality) {
176 if (PersonalityRef) {
177 // If the reference to the personality function symbol is not already
178 // pc-relative, then we need to subtract our current address from it. Do
179 // this by emitting a label and subtracting it from the expression we
180 // already have. This is equivalent to emitting "foo - .", but we have to
181 // emit the label for "." directly.
182 if (!IsPersonalityPCRel) {
183 SmallString<64> Name;
184 raw_svector_ostream(Name) << MAI->getPrivateGlobalPrefix()
185 << "personalityref_addr" << Asm->getFunctionNumber() << "_" << Index;
186 MCSymbol *DotSym = Asm->OutContext.GetOrCreateSymbol(Name.str());
187 Asm->OutStreamer.EmitLabel(DotSym);
188
189 PersonalityRef =
190 MCBinaryExpr::CreateSub(PersonalityRef,
191 MCSymbolRefExpr::Create(DotSym,Asm->OutContext),
192 Asm->OutContext);
193 }
194
162195 O << MAI->getData32bitsDirective();
163
164 O << MAI->getPersonalityPrefix();
165 O << Asm->Mang->getMangledName(Personality);
166 O << MAI->getPersonalitySuffix();
167
168 if (strcmp(MAI->getPersonalitySuffix(), "+4@GOTPCREL"))
169 O << "-" << MAI->getPCSymbol();
196 PersonalityRef->print(O, MAI);
170197 Asm->EOL("Personality");
171198
172199 Asm->EmitInt8(LSDAEncoding);
184211 // On Darwin the linker honors the alignment of eh_frame, which means it must
185212 // be 8-byte on 64-bit targets to match what gcc does. Otherwise you get
186213 // holes which confuse readers of eh_frame.
187 Asm->EmitAlignment(TD->getPointerSize() == sizeof(int32_t) ? 2 : 3,
188 0, 0, false);
214 Asm->EmitAlignment(TD->getPointerSize() == 4 ? 2 : 3, 0, 0, false);
189215 EmitLabel("eh_frame_common_end", Index);
190216
191217 Asm->EOL();
2929 GlobalPrefix = "";
3030 PrivateGlobalPrefix = ".";
3131 LinkerPrivateGlobalPrefix = "";
32 PersonalityPrefix = "";
33 PersonalitySuffix = "";
34 NeedsIndirectEncoding = false;
3532 InlineAsmStart = "APP";
3633 InlineAsmEnd = "NO_APP";
3734 AssemblerDialect = 0;
1919 // Syntax:
2020 GlobalPrefix = "_";
2121 PrivateGlobalPrefix = "L";
22 LinkerPrivateGlobalPrefix = "l"; // Marker for some ObjC metadata
22 LinkerPrivateGlobalPrefix = "l";
2323 NeedsSet = true;
24 NeedsIndirectEncoding = true;
2524 AllowQuotesInName = true;
2625 HasSingleParameterDotFile = false;
2726
2121 if (!is64Bit)
2222 Data64bitsDirective = 0; // We can't emit a 64-bit unit in PPC32 mode.
2323 AssemblerDialect = 1; // New-Style mnemonics.
24
25 PersonalityPrefix = "L";
26 PersonalitySuffix = "$non_lazy_ptr";
2724 }
2825
2926 PPCLinuxMCAsmInfo::PPCLinuxMCAsmInfo(bool is64Bit) {
1717 #include "llvm/Function.h"
1818 #include "llvm/GlobalVariable.h"
1919 #include "llvm/MC/MCContext.h"
20 #include "llvm/MC/MCExpr.h"
2021 #include "llvm/MC/MCSectionMachO.h"
2122 #include "llvm/MC/MCSectionELF.h"
2223 #include "llvm/Target/TargetData.h"
274275 return DataSection;
275276 }
276277
278 /// getSymbolForDwarfGlobalReference - Return an MCExpr to use for a
279 /// pc-relative reference to the specified global variable from exception
280 /// handling information. In addition to the symbol, this returns
281 /// by-reference:
282 ///
283 /// IsIndirect - True if the returned symbol is actually a stub that contains
284 /// the address of the symbol, false if the symbol is the global itself.
285 ///
286 /// IsPCRel - True if the symbol reference is already pc-relative, false if
287 /// the caller needs to subtract off the address of the reference from the
288 /// symbol.
289 ///
290 const MCExpr *TargetLoweringObjectFile::
291 getSymbolForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang,
292 bool &IsIndirect, bool &IsPCRel) const {
293 // The generic implementation of this just returns a direct reference to the
294 // symbol.
295 IsIndirect = false;
296 IsPCRel = false;
297
298 SmallString<128> Name;
299 Mang->getNameWithPrefix(Name, GV, false);
300 return MCSymbolRefExpr::Create(Name.str(), getContext());
301 }
277302
278303
279304 //===----------------------------------------------------------------------===//
926951 }
927952
928953 return true;
954 }
955
956 const MCExpr *TargetLoweringObjectFileMachO::
957 getSymbolForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang,
958 bool &IsIndirect, bool &IsPCRel) const {
959 // The mach-o version of this method defaults to returning a stub reference.
960 IsIndirect = true;
961 IsPCRel = false;
962
963 SmallString<128> Name;
964 Mang->getNameWithPrefix(Name, GV, true);
965 Name += "$non_lazy_ptr";
966 return MCSymbolRefExpr::Create(Name.str(), getContext());
929967 }
930968
931969
10451083
10461084 return getDataSection();
10471085 }
1086
1515 #include "X86InstrBuilder.h"
1616 #include "X86ISelLowering.h"
1717 #include "X86TargetMachine.h"
18 #include "X86TargetObjectFile.h"
1819 #include "llvm/CallingConv.h"
1920 #include "llvm/Constants.h"
2021 #include "llvm/DerivedTypes.h"
3536 #include "llvm/Support/MathExtras.h"
3637 #include "llvm/Support/Debug.h"
3738 #include "llvm/Support/ErrorHandling.h"
38 #include "llvm/Target/TargetLoweringObjectFile.h"
3939 #include "llvm/Target/TargetOptions.h"
4040 #include "llvm/ADT/SmallSet.h"
4141 #include "llvm/ADT/StringExtras.h"
6262 switch (TM.getSubtarget().TargetType) {
6363 default: llvm_unreachable("unknown subtarget type");
6464 case X86Subtarget::isDarwin:
65 if (TM.getSubtarget().is64Bit())
66 return new X8664_MachoTargetObjectFile();
6567 return new TargetLoweringObjectFileMachO();
6668 case X86Subtarget::isELF:
6769 return new TargetLoweringObjectFileELF();
5555
5656 // Leopard and above support aligned common symbols.
5757 COMMDirectiveTakesAlignment = Triple.getDarwinMajorNumber() >= 9;
58
59 if (is64Bit) {
60 PersonalityPrefix = "";
61 PersonalitySuffix = "+4@GOTPCREL";
62 } else {
63 PersonalityPrefix = "L";
64 PersonalitySuffix = "$non_lazy_ptr";
65 }
6658
6759 CommentString = "##";
6860 PCSymbol = ".";
0 //===-- llvm/Target/X86/X86TargetObjectFile.cpp - X86 Object Info ---------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "X86TargetObjectFile.h"
10 #include "llvm/ADT/SmallString.h"
11 #include "llvm/Support/Mangler.h"
12 #include "llvm/MC/MCExpr.h"
13 using namespace llvm;
14
15 const MCExpr *X8664_MachoTargetObjectFile::
16 getSymbolForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang,
17 bool &IsIndirect, bool &IsPCRel) const {
18
19 // On Darwin/X86-64, we can reference dwarf symbols with foo@GOTPCREL+4, which
20 // is an indirect pc-relative reference.
21 IsIndirect = true;
22 IsPCRel = true;
23
24 SmallString<128> Name;
25 Mang->getNameWithPrefix(Name, GV, false);
26 Name += "@GOTPCREL";
27 const MCExpr *Res =
28 MCSymbolRefExpr::Create(Name.str(), getContext());
29 const MCExpr *Four = MCConstantExpr::Create(4, getContext());
30 return MCBinaryExpr::CreateAdd(Res, Four, getContext());
31 }
32
0 //===-- llvm/Target/X86/X86TargetObjectFile.h - X86 Object Info -*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_TARGET_X86_TARGETOBJECTFILE_H
10 #define LLVM_TARGET_X86_TARGETOBJECTFILE_H
11
12 #include "llvm/Target/TargetLoweringObjectFile.h"
13
14 namespace llvm {
15
16 /// X8664_MachoTargetObjectFile - This TLOF implementation is used for
17 /// Darwin/x86-64.
18 class X8664_MachoTargetObjectFile : public TargetLoweringObjectFileMachO {
19 public:
20
21 virtual const MCExpr *
22 getSymbolForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang,
23 bool &IsIndirect, bool &IsPCRel) const;
24 };
25 } // end namespace llvm
26
27 #endif