Check return value of addOptionalSynthetic before calling a member function on it.

Found with UBSan.

llvm-svn: 268410
This commit is contained in:
Peter Collingbourne
2016-05-03 18:03:45 +00:00
parent 1ff4a0b7ee
commit 6f535b744f

View File

@@ -1207,9 +1207,11 @@ template <class ELFT> void Writer<ELFT>::addReservedSymbols() {
// On MIPS O32 ABI, _gp_disp is a magic symbol designates offset between
// start of function and 'gp' pointer into GOT.
ElfSym<ELFT>::MipsGpDisp =
addOptionalSynthetic(Symtab, "_gp_disp", Out<ELFT>::Got, MipsGPOffset)
->body();
Symbol *Sym =
addOptionalSynthetic(Symtab, "_gp_disp", Out<ELFT>::Got, MipsGPOffset);
if (Sym)
ElfSym<ELFT>::MipsGpDisp = Sym->body();
// The __gnu_local_gp is a magic symbol equal to the current value of 'gp'
// pointer. This symbol is used in the code generated by .cpload pseudo-op
// in case of using -mno-shared option.