Index: ELF/Relocations.cpp =================================================================== --- ELF/Relocations.cpp +++ ELF/Relocations.cpp @@ -762,12 +762,12 @@ // complicates things for the dynamic linker and means we would have to reserve // space for the extra PT_LOAD even if we end up not using it. template -static RelExpr processRelocAux(InputSectionBase &Sec, RelExpr Expr, - RelType Type, uint64_t Offset, Symbol &Sym, - const RelTy &Rel, int64_t Addend) { +static void processRelocAux(InputSectionBase &Sec, RelExpr Expr, RelType Type, + uint64_t Offset, Symbol &Sym, const RelTy &Rel, + int64_t Addend) { if (isStaticLinkTimeConstant(Expr, Type, Sym, Sec, Offset)) { Sec.Relocations.push_back({Expr, Type, Offset, Addend, &Sym}); - return Expr; + return; } bool CanWrite = (Sec.Flags & SHF_WRITE) || !Config->ZText; if (CanWrite) { @@ -777,7 +777,7 @@ if (!IsPreemptibleValue) { InX::RelaDyn->addReloc(Target->RelativeRel, &Sec, Offset, &Sym, Addend, Expr, Type); - return Expr; + return; } else if (RelType Rel = Target->getDynRel(Type)) { InX::RelaDyn->addReloc(Rel, &Sec, Offset, &Sym, Addend, R_ADDEND, Type); @@ -798,7 +798,7 @@ // ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf p.4-19 if (Config->EMachine == EM_MIPS) InX::MipsGot->addEntry(Sym, Addend, Expr); - return Expr; + return; } } @@ -806,7 +806,7 @@ // executable, give up on it and produce a non preemptible 0. if (!Config->Shared && Sym.isUndefWeak()) { Sec.Relocations.push_back({Expr, Type, Offset, Addend, &Sym}); - return Expr; + return; } if (!CanWrite && (Config->Pic && !isRelExpr(Expr))) { @@ -816,7 +816,7 @@ " in readonly segment; recompile object files with -fPIC " "or pass '-Wl,-z,notext' to allow text relocations in the output" + getLocation(Sec, Sym, Offset)); - return Expr; + return; } // Copy relocations are only possible if we are creating an executable. @@ -824,19 +824,19 @@ errorOrWarn("relocation " + toString(Type) + " cannot be used against symbol " + toString(Sym) + "; recompile with -fPIC" + getLocation(Sec, Sym, Offset)); - return Expr; + return; } // If the symbol is undefined we already reported any relevant errors. if (!Sym.isShared()) { assert(Sym.isUndefined()); - return Expr; + return; } if (!canDefineSymbolInExecutable(Sym)) { error("cannot preempt symbol: " + toString(Sym) + getLocation(Sec, Sym, Offset)); - return Expr; + return; } if (Sym.isObject()) { @@ -851,7 +851,7 @@ addCopyRelSymbol(SS); } Sec.Relocations.push_back({Expr, Type, Offset, Addend, &Sym}); - return Expr; + return; } if (Sym.isFunc()) { @@ -886,15 +886,16 @@ errorOrWarn("symbol '" + toString(Sym) + "' cannot be preempted; recompile with -fPIE" + getLocation(Sec, Sym, Offset)); + if (!Sym.isInPlt()) + addPltEntry(InX::Plt, InX::GotPlt, InX::RelaPlt, Target->PltRel, + Sym); Sym.NeedsPltAddr = true; - Expr = toPlt(Expr); - Sec.Relocations.push_back({Expr, Type, Offset, Addend, &Sym}); - return Expr; + Sec.Relocations.push_back({toPlt(Expr), Type, Offset, Addend, &Sym}); + return; } errorOrWarn("symbol '" + toString(Sym) + "' has no type" + getLocation(Sec, Sym, Offset)); - return Expr; } template @@ -963,7 +964,6 @@ return; } - Expr = processRelocAux(Sec, Expr, Type, Offset, Sym, Rel, Addend); // If a relocation needs PLT, we create PLT and GOTPLT slots for the symbol. if (needsPlt(Expr) && !Sym.isInPlt()) { if (Sym.isGnuIFunc() && !Sym.IsPreemptible) @@ -992,6 +992,8 @@ addGotEntry(Sym); } } + + processRelocAux(Sec, Expr, Type, Offset, Sym, Rel, Addend); } template Index: test/ELF/got32-i386-pie-rw.s =================================================================== --- test/ELF/got32-i386-pie-rw.s +++ test/ELF/got32-i386-pie-rw.s @@ -7,8 +7,8 @@ # CHECK: .foobar PROGBITS 00001000 # CHECK: .got PROGBITS [[GOT:[0-9a-z]*]] -# CHECK: 00001002 00000008 R_386_RELATIVE -# CHECK: [[GOT]] 00000008 R_386_RELATIVE +# CHECK-DAG: 00001002 00000008 R_386_RELATIVE +# CHECK-DAG: [[GOT]] 00000008 R_386_RELATIVE foo: .section .foobar, "awx"