llvm.org GIT mirror llvm / 1c9cd02
[CodeGen] prevent abnormal on invalid attributes Currently, when an invalid attribute is encountered on processing a .s file, clang will abort due to llvm_unreachable. Invalid user input should not cause an abnormal termination of the compiler. Change the interface to return a boolean to indicate the failure as a first step towards improving hanlding of malformed user input to clang. Signed-off-by: Saleem Abdulrasool <compnerd@compnerd.org> git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188047 91177308-0d34-0410-b5e6-96231b3b80d8 Saleem Abdulrasool 7 years ago
10 changed file(s) with 38 addition(s) and 24 deletion(s). Raw diff Collapse all Expand all
5656 virtual void EmitAssemblerFlag(MCAssemblerFlag Flag);
5757 virtual void EmitThumbFunc(MCSymbol *Func);
5858 virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol);
59 virtual void EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute);
59 virtual bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute);
6060 virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue);
6161 virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
6262 unsigned ByteAlignment);
322322 virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) = 0;
323323
324324 /// EmitSymbolAttribute - Add the given @p Attribute to @p Symbol.
325 virtual void EmitSymbolAttribute(MCSymbol *Symbol,
325 virtual bool EmitSymbolAttribute(MCSymbol *Symbol,
326326 MCSymbolAttr Attribute) = 0;
327327
328328 /// EmitSymbolDesc - Set the @p DescValue for the @p Symbol.
153153 virtual void EmitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel,
154154 const MCSymbol *Label);
155155
156 virtual void EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute);
156 virtual bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute);
157157
158158 virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue);
159159 virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol);
435435 }
436436
437437
438 void MCAsmStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
438 bool MCAsmStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
439439 MCSymbolAttr Attribute) {
440440 switch (Attribute) {
441441 case MCSA_Invalid: llvm_unreachable("Invalid symbol attribute");
446446 case MCSA_ELF_TypeCommon: /// .type _foo, STT_COMMON # aka @common
447447 case MCSA_ELF_TypeNoType: /// .type _foo, STT_NOTYPE # aka @notype
448448 case MCSA_ELF_TypeGnuUniqueObject: /// .type _foo, @gnu_unique_object
449 assert(MAI->hasDotTypeDotSizeDirective() && "Symbol Attr not supported");
449 if (!MAI->hasDotTypeDotSizeDirective())
450 return false; // Symbol attribute not supported
450451 OS << "\t.type\t" << *Symbol << ','
451452 << ((MAI->getCommentString()[0] != '@') ? '@' : '%');
452453 switch (Attribute) {
453 default: llvm_unreachable("Unknown ELF .type");
454 default: return false;
454455 case MCSA_ELF_TypeFunction: OS << "function"; break;
455456 case MCSA_ELF_TypeIndFunction: OS << "gnu_indirect_function"; break;
456457 case MCSA_ELF_TypeObject: OS << "object"; break;
460461 case MCSA_ELF_TypeGnuUniqueObject: OS << "gnu_unique_object"; break;
461462 }
462463 EmitEOL();
463 return;
464 return true;
464465 case MCSA_Global: // .globl/.global
465466 OS << MAI->getGlobalDirective();
466467 FlagMap[Symbol] |= EHGlobal;
490491
491492 OS << *Symbol;
492493 EmitEOL();
494
495 return true;
493496 }
494497
495498 void MCAsmStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
147147 return T2;
148148 }
149149
150 void MCELFStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
151 MCSymbolAttr Attribute) {
150 bool MCELFStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
151 MCSymbolAttr Attribute) {
152152 // Indirect symbols are handled differently, to match how 'as' handles
153153 // them. This makes writing matching .o files easier.
154154 if (Attribute == MCSA_IndirectSymbol) {
158158 ISD.Symbol = Symbol;
159159 ISD.SectionData = getCurrentSectionData();
160160 getAssembler().getIndirectSymbols().push_back(ISD);
161 return;
161 return true;
162162 }
163163
164164 // Adding a symbol attribute always introduces the symbol, note that an
181181 case MCSA_WeakDefAutoPrivate:
182182 case MCSA_Invalid:
183183 case MCSA_IndirectSymbol:
184 llvm_unreachable("Invalid symbol attribute for ELF!");
184 return false;
185185
186186 case MCSA_NoDeadStrip:
187187 case MCSA_ELF_TypeGnuUniqueObject:
250250 MCELF::SetVisibility(SD, ELF::STV_INTERNAL);
251251 break;
252252 }
253
254 return true;
253255 }
254256
255257 void MCELFStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
5050 virtual void EmitLinkerOptions(ArrayRef Options);
5151 virtual void EmitDataRegion(MCDataRegionType Kind);
5252 virtual void EmitThumbFunc(MCSymbol *Func);
53 virtual void EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute);
53 virtual bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute);
5454 virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue);
5555 virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
5656 unsigned ByteAlignment);
216216 SD.setFlags(SD.getFlags() | SF_ThumbFunc);
217217 }
218218
219 void MCMachOStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
219 bool MCMachOStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
220220 MCSymbolAttr Attribute) {
221221 // Indirect symbols are handled differently, to match how 'as' handles
222222 // them. This makes writing matching .o files easier.
227227 ISD.Symbol = Symbol;
228228 ISD.SectionData = getCurrentSectionData();
229229 getAssembler().getIndirectSymbols().push_back(ISD);
230 return;
230 return true;
231231 }
232232
233233 // Adding a symbol attribute always introduces the symbol, note that an
256256 case MCSA_Protected:
257257 case MCSA_Weak:
258258 case MCSA_Local:
259 llvm_unreachable("Invalid symbol attribute for Mach-O!");
259 return false;
260260
261261 case MCSA_Global:
262262 SD.setExternal(true);
308308 SD.setFlags(SD.getFlags() | SF_WeakDefinition | SF_WeakReference);
309309 break;
310310 }
311
312 return true;
311313 }
312314
313315 void MCMachOStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
5151 const MCSymbol *Label,
5252 unsigned PointerSize) {}
5353
54 virtual void EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute){}
54 virtual bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute){
55 return true;
56 }
5557
5658 virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {}
5759
33743374 if (Sym->isTemporary())
33753375 return Error(Loc, "non-local symbol required in directive");
33763376
3377 getStreamer().EmitSymbolAttribute(Sym, Attr);
3377 if (!getStreamer().EmitSymbolAttribute(Sym, Attr))
3378 return Error(Loc, "unable to emit symbol attribute");
33783379
33793380 if (getLexer().is(AsmToken::EndOfStatement))
33803381 break;
5050 virtual void FinishImpl();
5151
5252
53 virtual void EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) {
54 report_fatal_error("unsupported directive in pure streamer");
53 virtual bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) {
54 report_fatal_error("unsupported directive in pure streamer");
55 return false;
5556 }
5657 virtual void EmitAssemblerFlag(MCAssemblerFlag Flag) {
5758 report_fatal_error("unsupported directive in pure streamer");
5454 virtual void EmitDebugLabel(MCSymbol *Symbol);
5555 virtual void EmitAssemblerFlag(MCAssemblerFlag Flag);
5656 virtual void EmitThumbFunc(MCSymbol *Func);
57 virtual void EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute);
57 virtual bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute);
5858 virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue);
5959 virtual void BeginCOFFSymbolDef(MCSymbol const *Symbol);
6060 virtual void EmitCOFFSymbolStorageClass(int StorageClass);
200200 llvm_unreachable("not implemented");
201201 }
202202
203 void WinCOFFStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
203 bool WinCOFFStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
204204 MCSymbolAttr Attribute) {
205205 assert(Symbol && "Symbol must be non-null!");
206206 assert((Symbol->isInSection()
220220 break;
221221
222222 default:
223 llvm_unreachable("unsupported attribute");
224 }
223 return false;
224 }
225
226 return true;
225227 }
226228
227229 void WinCOFFStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
737737 // FIXME: should we handle aliases?
738738 markDefined(*Symbol);
739739 }
740 virtual void EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) {
740 virtual bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) {
741741 if (Attribute == MCSA_Global)
742742 markGlobal(*Symbol);
743 return true;
743744 }
744745 virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol,
745746 uint64_t Size , unsigned ByteAlignment) {