diff --git a/src/p_armpe.cpp b/src/p_armpe.cpp index 60b1d912..59d064e5 100644 --- a/src/p_armpe.cpp +++ b/src/p_armpe.cpp @@ -228,7 +228,7 @@ unsigned PackArmPe::getProcessImportParam(unsigned upxsection) } void PackArmPe::defineSymbols(unsigned ncsection, unsigned, unsigned, - unsigned ic, Reloc &, unsigned s1addr) + unsigned ic, unsigned s1addr) { const unsigned onam = ncsection + soxrelocs + ih.imagebase; linker->defineSymbol("start_of_dll_names", onam); diff --git a/src/p_armpe.h b/src/p_armpe.h index fa79ff89..fadc56b5 100644 --- a/src/p_armpe.h +++ b/src/p_armpe.h @@ -53,7 +53,7 @@ public: unsigned ih_codebase); virtual void defineSymbols(unsigned ncsection, unsigned upxsection, unsigned sizeof_oh, unsigned isize_isplit, - Reloc &rel, unsigned s1addr); + unsigned s1addr); virtual void addNewRelocations(Reloc &, unsigned upxsection); virtual unsigned getProcessImportParam(unsigned upxsection); virtual void setOhDataBase(const pe_section_t *osection); diff --git a/src/p_w32pe.cpp b/src/p_w32pe.cpp index 397d0c27..63784fef 100644 --- a/src/p_w32pe.cpp +++ b/src/p_w32pe.cpp @@ -189,7 +189,7 @@ bool PackW32Pe::handleForceOption() void PackW32Pe::defineSymbols(unsigned ncsection, unsigned upxsection, unsigned sizeof_oh, unsigned ic, - Reloc &, unsigned s1addr) + unsigned s1addr) { const unsigned myimport = ncsection + soresources - rvamin; @@ -269,12 +269,6 @@ void PackW32Pe::defineSymbols(unsigned ncsection, unsigned upxsection, void PackW32Pe::addNewRelocations(Reloc &rel, unsigned) { rel.add(linker->getSymbolOffset("PEMAIN01") + 2, 3); - if (use_tls_callbacks) - { - tls_handler_offset = linker->getSymbolOffset("PETLSC2"); - //add relocation entry for TLS callback handler - rel.add(tls_handler_offset + 4, 3); - } } void PackW32Pe::setOhDataBase(const pe_section_t *osection) diff --git a/src/p_w32pe.h b/src/p_w32pe.h index a2fd8d62..907972e8 100644 --- a/src/p_w32pe.h +++ b/src/p_w32pe.h @@ -50,7 +50,7 @@ public: virtual bool handleForceOption(); virtual void defineSymbols(unsigned ncsection, unsigned upxsection, unsigned sizeof_oh, unsigned isize_isplit, - Reloc &rel, unsigned s1addr); + unsigned s1addr); virtual void addNewRelocations(Reloc &, unsigned upxsection); virtual void setOhDataBase(const pe_section_t *osection); virtual void setOhHeaderSize(const pe_section_t *osection); diff --git a/src/p_w64pep.cpp b/src/p_w64pep.cpp index 8fc3cd8c..3ecc1067 100644 --- a/src/p_w64pep.cpp +++ b/src/p_w64pep.cpp @@ -188,7 +188,7 @@ bool PackW64Pep::handleForceOption() void PackW64Pep::defineSymbols(unsigned ncsection, unsigned upxsection, unsigned sizeof_oh, unsigned ic, - Reloc &, unsigned s1addr) + unsigned s1addr) { const unsigned myimport = ncsection + soresources - rvamin; diff --git a/src/p_w64pep.h b/src/p_w64pep.h index b1803841..8d168cb5 100644 --- a/src/p_w64pep.h +++ b/src/p_w64pep.h @@ -49,7 +49,7 @@ public: virtual bool handleForceOption(); virtual void defineSymbols(unsigned ncsection, unsigned upxsection, unsigned sizeof_oh, unsigned isize_isplit, - Reloc &rel, unsigned s1addr); + unsigned s1addr); virtual void setOhDataBase(const pe_section_t *) {} virtual void setOhHeaderSize(const pe_section_t *osection); virtual void pack(OutputFile *fo); diff --git a/src/pefile.cpp b/src/pefile.cpp index 422b5aee..77f06d92 100644 --- a/src/pefile.cpp +++ b/src/pefile.cpp @@ -1229,6 +1229,7 @@ struct PeFile::tls_traits static const unsigned cb_size = 4; typedef unsigned cb_value_t; static const unsigned reloc_type = 3; + static const int tls_handler_offset_reloc = 4; }; template <> @@ -1246,6 +1247,7 @@ struct PeFile::tls_traits static const unsigned cb_size = 8; typedef upx_uint64_t cb_value_t; static const unsigned reloc_type = 10; + static const int tls_handler_offset_reloc = -1; // no need to relocate }; template @@ -1333,10 +1335,15 @@ void PeFile::processTls2(Reloc *rel,const Interval *iv,unsigned newaddr, typedef typename tls_traits::cb_value_t cb_value_t; const unsigned cb_size = tls_traits::cb_size; const unsigned reloc_type = tls_traits::reloc_type; + const int tls_handler_offset_reloc = tls_traits::tls_handler_offset_reloc; if (sotls == 0) return; // add new relocation entries + + if (tls_handler_offset_reloc > 0) + rel->add(tls_handler_offset + tls_handler_offset_reloc, reloc_type); + unsigned ic; //NEW: if TLS callbacks are used, relocate the VA of the callback chain, too - Stefan Widmann for (ic = 0; ic < (use_tls_callbacks ? 4 * cb_size : 3 * cb_size); ic += cb_size) @@ -2328,6 +2335,10 @@ void PeFile::pack0(OutputFile *fo, ht &ih, ht &oh, // tls & loadconf are put into section 1 ic = s1addr + s1size - sotls - soloadconf; + + if (use_tls_callbacks) + tls_handler_offset = linker->getSymbolOffset("PETLSC2") + upxsection; + processTls(&rel,&tlsiv,ic); ODADDR(PEDIR_TLS) = sotls ? ic : 0; ODSIZE(PEDIR_TLS) = sotls ? (sizeof(LEXX) == 4 ? 0x18 : 0x28) : 0; @@ -2370,7 +2381,7 @@ void PeFile::pack0(OutputFile *fo, ht &ih, ht &oh, callProcessResources(res, ic = res_start); defineSymbols(ncsection, upxsection, sizeof(oh), - identsize - identsplit, rel, s1addr); + identsize - identsplit, s1addr); defineFilterSymbols(&ft); relocateLoader(); const unsigned lsize = getLoaderSize(); diff --git a/src/pefile.h b/src/pefile.h index 2092dd71..22b3d4d5 100644 --- a/src/pefile.h +++ b/src/pefile.h @@ -63,7 +63,7 @@ protected: unsigned ih_codebase); virtual void defineSymbols(unsigned ncsection, unsigned upxsection, unsigned sizeof_oh, unsigned isize_isplit, - Reloc &rel, unsigned s1addr) = 0; + unsigned s1addr) = 0; virtual void addNewRelocations(Reloc &, unsigned) {} void callProcessRelocs(Reloc &rel, unsigned &ic); void callProcessResources(Resource &res, unsigned &ic);