llvm.org GIT mirror llvm / 8aa3ff0
[COFF] Add support for the .secidx directive Reviewed at http://llvm-reviews.chandlerc.com/D2445 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@197826 91177308-0d34-0410-b5e6-96231b3b80d8 Timur Iskhodzhanov 6 years ago
7 changed file(s) with 66 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
3636 Relocations
3737 ^^^^^^^^^^^
3838
39 The following additional relocation type is supported:
39 The following additional relocation types are supported:
4040
4141 **@IMGREL** (AT&T syntax only) generates an image-relative relocation that
4242 corresponds to the COFF relocation types ``IMAGE_REL_I386_DIR32NB`` (32-bit) or
5353 .long (fun@imgrel + 0x3F)
5454 .long $unwind$fun@imgrel
5555
56 **.secrel32** generates a relocation that corresponds to the COFF relocation
57 types ``IMAGE_REL_I386_SECREL`` (32-bit) or ``IMAGE_REL_AMD64_SECREL`` (64-bit).
58
59 **.secidx** relocation generates an index of the section that contains
60 the target. It corresponds to the COFF relocation types
61 ``IMAGE_REL_I386_SECTION`` (32-bit) or ``IMAGE_REL_AMD64_SECTION`` (64-bit).
62
63 .. code-block:: gas
64
65 .section .debug$S,"rn"
66 .long 4
67 .long 242
68 .long 40
69 .secrel32 _function_name
70 .secidx _function_name
71 ...
5672
5773 ``.linkonce`` Directive
5874 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
409409
410410 /// EndCOFFSymbolDef - Marks the end of the symbol definition.
411411 virtual void EndCOFFSymbolDef() = 0;
412
413 /// EmitCOFFSectionIndex - Emits a COFF section index.
414 ///
415 /// @param Symbol - Symbol the section number relocation should point to.
416 virtual void EmitCOFFSectionIndex(MCSymbol const *Symbol);
412417
413418 /// EmitCOFFSecRel32 - Emits a COFF section relative relocation.
414419 ///
159159 virtual void EmitCOFFSymbolStorageClass(int StorageClass);
160160 virtual void EmitCOFFSymbolType(int Type);
161161 virtual void EndCOFFSymbolDef();
162 virtual void EmitCOFFSectionIndex(MCSymbol const *Symbol);
162163 virtual void EmitCOFFSecRel32(MCSymbol const *Symbol);
163164 virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value);
164165 virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
504505 EmitEOL();
505506 }
506507
508 void MCAsmStreamer::EmitCOFFSectionIndex(MCSymbol const *Symbol) {
509 OS << "\t.secidx\t" << *Symbol;
510 EmitEOL();
511 }
512
507513 void MCAsmStreamer::EmitCOFFSecRel32(MCSymbol const *Symbol) {
508 OS << "\t.secrel32\t" << *Symbol << '\n';
514 OS << "\t.secrel32\t" << *Symbol;
509515 EmitEOL();
510516 }
511517
5454 addDirectiveHandler<&COFFAsmParser::ParseDirectiveType>(".type");
5555 addDirectiveHandler<&COFFAsmParser::ParseDirectiveEndef>(".endef");
5656 addDirectiveHandler<&COFFAsmParser::ParseDirectiveSecRel32>(".secrel32");
57 addDirectiveHandler<&COFFAsmParser::ParseDirectiveSecIdx>(".secidx");
5758 addDirectiveHandler<&COFFAsmParser::ParseDirectiveLinkOnce>(".linkonce");
5859
5960 // Win64 EH directives.
114115 bool ParseDirectiveType(StringRef, SMLoc);
115116 bool ParseDirectiveEndef(StringRef, SMLoc);
116117 bool ParseDirectiveSecRel32(StringRef, SMLoc);
118 bool ParseDirectiveSecIdx(StringRef, SMLoc);
117119 bool parseCOMDATTypeAndAssoc(COFF::COMDATType &Type,
118120 const MCSectionCOFF *&Assoc);
119121 bool ParseDirectiveLinkOnce(StringRef, SMLoc);
431433 bool COFFAsmParser::ParseDirectiveSecRel32(StringRef, SMLoc) {
432434 StringRef SymbolID;
433435 if (getParser().parseIdentifier(SymbolID))
434 return true;
436 return TokError("expected identifier in directive");
435437
436438 if (getLexer().isNot(AsmToken::EndOfStatement))
437439 return TokError("unexpected token in directive");
440442
441443 Lex();
442444 getStreamer().EmitCOFFSecRel32(Symbol);
445 return false;
446 }
447
448 bool COFFAsmParser::ParseDirectiveSecIdx(StringRef, SMLoc) {
449 StringRef SymbolID;
450 if (getParser().parseIdentifier(SymbolID))
451 return TokError("expected identifier in directive");
452
453 if (getLexer().isNot(AsmToken::EndOfStatement))
454 return TokError("unexpected token in directive");
455
456 MCSymbol *Symbol = getContext().GetOrCreateSymbol(SymbolID);
457
458 Lex();
459 getStreamer().EmitCOFFSectionIndex(Symbol);
443460 return false;
444461 }
445462
565565 EmitLabel(CurFrame->PrologEnd);
566566 }
567567
568 void MCStreamer::EmitCOFFSectionIndex(MCSymbol const *Symbol) {
569 llvm_unreachable("This file format doesn't support this directive");
570 }
571
568572 void MCStreamer::EmitCOFFSecRel32(MCSymbol const *Symbol) {
569573 llvm_unreachable("This file format doesn't support this directive");
570574 }
6060 virtual void EmitCOFFSymbolStorageClass(int StorageClass);
6161 virtual void EmitCOFFSymbolType(int Type);
6262 virtual void EndCOFFSymbolDef();
63 virtual void EmitCOFFSectionIndex(MCSymbol const *Symbol);
6364 virtual void EmitCOFFSecRel32(MCSymbol const *Symbol);
6465 virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value);
6566 virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
248249 CurSymbol = NULL;
249250 }
250251
252 void WinCOFFStreamer::EmitCOFFSectionIndex(MCSymbol const *Symbol)
253 {
254 MCDataFragment *DF = getOrCreateDataFragment();
255
256 DF->getFixups().push_back(
257 MCFixup::Create(DF->getContents().size(),
258 MCSymbolRefExpr::Create (Symbol, getContext ()),
259 FK_SecRel_2));
260 DF->getContents().resize(DF->getContents().size() + 4, 0);
261 }
262
251263 void WinCOFFStreamer::EmitCOFFSecRel32(MCSymbol const *Symbol)
252264 {
253265 MCDataFragment *DF = getOrCreateDataFragment();
6464 if (Is64Bit)
6565 return COFF::IMAGE_REL_AMD64_ADDR64;
6666 llvm_unreachable("unsupported relocation type");
67 case FK_SecRel_2:
68 return Is64Bit ? COFF::IMAGE_REL_AMD64_SECTION
69 : COFF::IMAGE_REL_I386_SECTION;
6770 case FK_SecRel_4:
6871 return Is64Bit ? COFF::IMAGE_REL_AMD64_SECREL : COFF::IMAGE_REL_I386_SECREL;
6972 default: