Index: ELF/Config.h =================================================================== --- ELF/Config.h +++ ELF/Config.h @@ -1,3 +1,4 @@ + //===- Config.h -------------------------------------------------*- C++ -*-===// // // The LLVM Linker @@ -103,6 +104,7 @@ bool StripAll; bool StripDebug; bool SysvHash = true; + bool Target1Rel; bool Threads; bool Trace; bool Verbose; Index: ELF/Driver.cpp =================================================================== --- ELF/Driver.cpp +++ ELF/Driver.cpp @@ -364,6 +364,7 @@ Config->Shared = Args.hasArg(OPT_shared); Config->StripAll = Args.hasArg(OPT_strip_all); Config->StripDebug = Args.hasArg(OPT_strip_debug); + Config->Target1Rel = Args.hasArg(OPT_target1_rel); Config->Threads = Args.hasArg(OPT_threads); Config->Trace = Args.hasArg(OPT_trace); Config->Verbose = Args.hasArg(OPT_verbose); Index: ELF/Options.td =================================================================== --- ELF/Options.td +++ ELF/Options.td @@ -146,6 +146,10 @@ def sysroot: J<"sysroot=">, HelpText<"Set the system root">; +def target1_rel: F<"target1-rel">, HelpText<"Interpret R_ARM_TARGET1 as R_ARM_REL32">; + +def target1_abs: F<"target1-abs">, HelpText<"Interpret R_ARM_TARGET1 as R_ARM_ABS32">; + def threads: F<"threads">, HelpText<"Enable use of threads">; def trace: F<"trace">, HelpText<"Print the names of the input files">; Index: ELF/Relocations.cpp =================================================================== --- ELF/Relocations.cpp +++ ELF/Relocations.cpp @@ -535,7 +535,7 @@ for (auto I = Rels.begin(), E = Rels.end(); I != E; ++I) { const RelTy &RI = *I; SymbolBody &Body = File.getRelocTargetSym(RI); - uint32_t Type = RI.getType(Config->Mips64EL); + uint32_t Type = Target->modifyReloc(RI.getType(Config->Mips64EL)); RelExpr Expr = Target->getRelExpr(Type, Body); bool Preemptible = isPreemptible(Body, Type); Index: ELF/Target.h =================================================================== --- ELF/Target.h +++ ELF/Target.h @@ -27,6 +27,7 @@ virtual bool isTlsLocalDynamicRel(uint32_t Type) const; virtual bool isTlsGlobalDynamicRel(uint32_t Type) const; virtual uint32_t getDynRel(uint32_t Type) const { return Type; } + virtual uint32_t modifyReloc(uint32_t Type) const { return Type; } virtual void writeGotPltHeader(uint8_t *Buf) const {} virtual void writeGotPlt(uint8_t *Buf, const SymbolBody &S) const {}; virtual uint64_t getImplicitAddend(const uint8_t *Buf, uint32_t Type) const; Index: ELF/Target.cpp =================================================================== --- ELF/Target.cpp +++ ELF/Target.cpp @@ -177,6 +177,7 @@ ARMTargetInfo(); RelExpr getRelExpr(uint32_t Type, const SymbolBody &S) const override; uint32_t getDynRel(uint32_t Type) const override; + uint32_t modifyReloc(uint32_t Type) const override; uint64_t getImplicitAddend(const uint8_t *Buf, uint32_t Type) const override; bool isTlsLocalDynamicRel(uint32_t Type) const override; bool isTlsGlobalDynamicRel(uint32_t Type) const override; @@ -1502,6 +1503,12 @@ NeedsThunks = true; } +uint32_t ARMTargetInfo::modifyReloc(uint32_t Type) const { + if (Type == R_ARM_TARGET1) + return (Config->Target1Rel) ? R_ARM_REL32 : R_ARM_ABS32; + return Type; +} + RelExpr ARMTargetInfo::getRelExpr(uint32_t Type, const SymbolBody &S) const { switch (Type) { default: