src: cleanup linker.h
This commit is contained in:
+1
-5
@@ -101,11 +101,7 @@ ElfLinker::Relocation::Relocation(const Section *s, unsigned o, const char *t, c
|
|||||||
// ElfLinker
|
// ElfLinker
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
ElfLinker::ElfLinker()
|
ElfLinker::ElfLinker(const N_BELE_RTP::AbstractPolicy *b) noexcept : bele(b) {}
|
||||||
: bele(&N_BELE_RTP::le_policy), input(nullptr), output(nullptr), head(nullptr), tail(nullptr),
|
|
||||||
sections(nullptr), symbols(nullptr), relocations(nullptr), nsections(0),
|
|
||||||
nsections_capacity(0), nsymbols(0), nsymbols_capacity(0), nrelocations(0),
|
|
||||||
nrelocations_capacity(0), reloc_done(false) {}
|
|
||||||
|
|
||||||
ElfLinker::~ElfLinker() noexcept {
|
ElfLinker::~ElfLinker() noexcept {
|
||||||
delete[] input;
|
delete[] input;
|
||||||
|
|||||||
+15
-51
@@ -25,8 +25,7 @@
|
|||||||
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __UPX_LINKER_H
|
#pragma once
|
||||||
#define __UPX_LINKER_H 1
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// ElfLinker
|
// ElfLinker
|
||||||
@@ -36,7 +35,7 @@ class ElfLinker : private noncopyable {
|
|||||||
friend class Packer;
|
friend class Packer;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
const N_BELE_RTP::AbstractPolicy *bele = nullptr; // target endianness
|
const N_BELE_RTP::AbstractPolicy *const bele; // target endianness
|
||||||
protected:
|
protected:
|
||||||
struct Section;
|
struct Section;
|
||||||
struct Symbol;
|
struct Symbol;
|
||||||
@@ -76,7 +75,7 @@ protected:
|
|||||||
const char *symbol, upx_uint64_t add);
|
const char *symbol, upx_uint64_t add);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ElfLinker();
|
ElfLinker(const N_BELE_RTP::AbstractPolicy *b = &N_BELE_RTP::le_policy) noexcept;
|
||||||
virtual ~ElfLinker() noexcept;
|
virtual ~ElfLinker() noexcept;
|
||||||
|
|
||||||
void init(const void *pdata, int plen, unsigned pxtra = 0);
|
void init(const void *pdata, int plen, unsigned pxtra = 0);
|
||||||
@@ -113,14 +112,6 @@ protected:
|
|||||||
void relocate();
|
void relocate();
|
||||||
virtual void relocate1(const Relocation *, byte *location, upx_uint64_t value,
|
virtual void relocate1(const Relocation *, byte *location, upx_uint64_t value,
|
||||||
const char *type);
|
const char *type);
|
||||||
|
|
||||||
// target endianness abstraction
|
|
||||||
unsigned get_te16(const void *p) const { return bele->get16(p); }
|
|
||||||
unsigned get_te32(const void *p) const { return bele->get32(p); }
|
|
||||||
upx_uint64_t get_te64(const void *p) const { return bele->get64(p); }
|
|
||||||
void set_te16(void *p, unsigned v) const { bele->set16(p, v); }
|
|
||||||
void set_te32(void *p, unsigned v) const { bele->set32(p, v); }
|
|
||||||
void set_te64(void *p, upx_uint64_t v) const { bele->set64(p, v); }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ElfLinker::Section : private noncopyable {
|
struct ElfLinker::Section : private noncopyable {
|
||||||
@@ -162,28 +153,23 @@ struct ElfLinker::Relocation : private noncopyable {
|
|||||||
|
|
||||||
class ElfLinkerAMD64 : public ElfLinker {
|
class ElfLinkerAMD64 : public ElfLinker {
|
||||||
typedef ElfLinker super;
|
typedef ElfLinker super;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void alignCode(unsigned len) override { alignWithByte(len, 0x90); }
|
virtual void alignCode(unsigned len) override { alignWithByte(len, 0x90); }
|
||||||
virtual void relocate1(const Relocation *, byte *location, upx_uint64_t value,
|
virtual void relocate1(const Relocation *, byte *location, upx_uint64_t value,
|
||||||
const char *type) override;
|
const char *type) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ElfLinkerARM64 final : public ElfLinker {
|
class ElfLinkerArm64LE final : public ElfLinker {
|
||||||
typedef ElfLinker super;
|
typedef ElfLinker super;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void alignCode(unsigned len) override { alignWithByte(len, 0x90); }
|
|
||||||
virtual void relocate1(const Relocation *, byte *location, upx_uint64_t value,
|
virtual void relocate1(const Relocation *, byte *location, upx_uint64_t value,
|
||||||
const char *type) override;
|
const char *type) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ElfLinkerArmBE final : public ElfLinker {
|
class ElfLinkerArmBE final : public ElfLinker {
|
||||||
typedef ElfLinker super;
|
typedef ElfLinker super;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ElfLinkerArmBE() { bele = &N_BELE_RTP::be_policy; }
|
ElfLinkerArmBE() noexcept : super(&N_BELE_RTP::be_policy) {}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void relocate1(const Relocation *, byte *location, upx_uint64_t value,
|
virtual void relocate1(const Relocation *, byte *location, upx_uint64_t value,
|
||||||
const char *type) override;
|
const char *type) override;
|
||||||
@@ -191,15 +177,6 @@ protected:
|
|||||||
|
|
||||||
class ElfLinkerArmLE final : public ElfLinker {
|
class ElfLinkerArmLE final : public ElfLinker {
|
||||||
typedef ElfLinker super;
|
typedef ElfLinker super;
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual void relocate1(const Relocation *, byte *location, upx_uint64_t value,
|
|
||||||
const char *type) override;
|
|
||||||
};
|
|
||||||
|
|
||||||
class ElfLinkerArm64LE final : public ElfLinker {
|
|
||||||
typedef ElfLinker super;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void relocate1(const Relocation *, byte *location, upx_uint64_t value,
|
virtual void relocate1(const Relocation *, byte *location, upx_uint64_t value,
|
||||||
const char *type) override;
|
const char *type) override;
|
||||||
@@ -207,10 +184,8 @@ protected:
|
|||||||
|
|
||||||
class ElfLinkerM68k final : public ElfLinker {
|
class ElfLinkerM68k final : public ElfLinker {
|
||||||
typedef ElfLinker super;
|
typedef ElfLinker super;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ElfLinkerM68k() { bele = &N_BELE_RTP::be_policy; }
|
ElfLinkerM68k() noexcept : super(&N_BELE_RTP::be_policy) {}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void alignCode(unsigned len) override;
|
virtual void alignCode(unsigned len) override;
|
||||||
virtual void relocate1(const Relocation *, byte *location, upx_uint64_t value,
|
virtual void relocate1(const Relocation *, byte *location, upx_uint64_t value,
|
||||||
@@ -219,10 +194,8 @@ protected:
|
|||||||
|
|
||||||
class ElfLinkerMipsBE final : public ElfLinker {
|
class ElfLinkerMipsBE final : public ElfLinker {
|
||||||
typedef ElfLinker super;
|
typedef ElfLinker super;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ElfLinkerMipsBE() { bele = &N_BELE_RTP::be_policy; }
|
ElfLinkerMipsBE() noexcept : super(&N_BELE_RTP::be_policy) {}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void relocate1(const Relocation *, byte *location, upx_uint64_t value,
|
virtual void relocate1(const Relocation *, byte *location, upx_uint64_t value,
|
||||||
const char *type) override;
|
const char *type) override;
|
||||||
@@ -230,7 +203,6 @@ protected:
|
|||||||
|
|
||||||
class ElfLinkerMipsLE final : public ElfLinker {
|
class ElfLinkerMipsLE final : public ElfLinker {
|
||||||
typedef ElfLinker super;
|
typedef ElfLinker super;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void relocate1(const Relocation *, byte *location, upx_uint64_t value,
|
virtual void relocate1(const Relocation *, byte *location, upx_uint64_t value,
|
||||||
const char *type) override;
|
const char *type) override;
|
||||||
@@ -238,18 +210,8 @@ protected:
|
|||||||
|
|
||||||
class ElfLinkerPpc32 final : public ElfLinker {
|
class ElfLinkerPpc32 final : public ElfLinker {
|
||||||
typedef ElfLinker super;
|
typedef ElfLinker super;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ElfLinkerPpc32() { bele = &N_BELE_RTP::be_policy; }
|
ElfLinkerPpc32() noexcept : super(&N_BELE_RTP::be_policy) {}
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual void relocate1(const Relocation *, byte *location, upx_uint64_t value,
|
|
||||||
const char *type) override;
|
|
||||||
};
|
|
||||||
|
|
||||||
class ElfLinkerPpc64le final : public ElfLinker {
|
|
||||||
typedef ElfLinker super;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void relocate1(const Relocation *, byte *location, upx_uint64_t value,
|
virtual void relocate1(const Relocation *, byte *location, upx_uint64_t value,
|
||||||
const char *type) override;
|
const char *type) override;
|
||||||
@@ -257,10 +219,15 @@ protected:
|
|||||||
|
|
||||||
class ElfLinkerPpc64 final : public ElfLinker {
|
class ElfLinkerPpc64 final : public ElfLinker {
|
||||||
typedef ElfLinker super;
|
typedef ElfLinker super;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ElfLinkerPpc64() { bele = &N_BELE_RTP::be_policy; }
|
ElfLinkerPpc64() noexcept : super(&N_BELE_RTP::be_policy) {}
|
||||||
|
protected:
|
||||||
|
virtual void relocate1(const Relocation *, byte *location, upx_uint64_t value,
|
||||||
|
const char *type) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
class ElfLinkerPpc64le final : public ElfLinker {
|
||||||
|
typedef ElfLinker super;
|
||||||
protected:
|
protected:
|
||||||
virtual void relocate1(const Relocation *, byte *location, upx_uint64_t value,
|
virtual void relocate1(const Relocation *, byte *location, upx_uint64_t value,
|
||||||
const char *type) override;
|
const char *type) override;
|
||||||
@@ -268,13 +235,10 @@ protected:
|
|||||||
|
|
||||||
class ElfLinkerX86 final : public ElfLinker {
|
class ElfLinkerX86 final : public ElfLinker {
|
||||||
typedef ElfLinker super;
|
typedef ElfLinker super;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void alignCode(unsigned len) override { alignWithByte(len, 0x90); }
|
virtual void alignCode(unsigned len) override { alignWithByte(len, 0x90); }
|
||||||
virtual void relocate1(const Relocation *, byte *location, upx_uint64_t value,
|
virtual void relocate1(const Relocation *, byte *location, upx_uint64_t value,
|
||||||
const char *type) override;
|
const char *type) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* already included */
|
|
||||||
|
|
||||||
/* vim:set ts=4 sw=4 et: */
|
/* vim:set ts=4 sw=4 et: */
|
||||||
|
|||||||
+1
-1
@@ -379,7 +379,7 @@ PackLinuxI386::buildLinuxLoader(
|
|||||||
(res->lit_context_bits << 0) |
|
(res->lit_context_bits << 0) |
|
||||||
(res->lit_pos_bits << 8) |
|
(res->lit_pos_bits << 8) |
|
||||||
(res->pos_bits << 16);
|
(res->pos_bits << 16);
|
||||||
if (linker->bele->isBE()) // big endian - bswap32
|
if (bele->isBE()) // big endian - bswap32
|
||||||
properties = bswap32(properties);
|
properties = bswap32(properties);
|
||||||
linker->defineSymbol("lzma_properties", properties);
|
linker->defineSymbol("lzma_properties", properties);
|
||||||
// -2 for properties
|
// -2 for properties
|
||||||
|
|||||||
+1
-1
@@ -595,7 +595,7 @@ void PackBvmlinuzI386::pack(OutputFile *fo)
|
|||||||
(res->lit_context_bits << 0) |
|
(res->lit_context_bits << 0) |
|
||||||
(res->lit_pos_bits << 8) |
|
(res->lit_pos_bits << 8) |
|
||||||
(res->pos_bits << 16);
|
(res->pos_bits << 16);
|
||||||
if (linker->bele->isBE()) // big endian - bswap32
|
if (bele->isBE()) // big endian - bswap32
|
||||||
properties = bswap32(properties);
|
properties = bswap32(properties);
|
||||||
linker->defineSymbol("lzma_properties", properties);
|
linker->defineSymbol("lzma_properties", properties);
|
||||||
// -2 for properties
|
// -2 for properties
|
||||||
|
|||||||
+1
-1
@@ -257,7 +257,7 @@ void Packer::defineDecompressorSymbols()
|
|||||||
(res->lit_context_bits << 0) |
|
(res->lit_context_bits << 0) |
|
||||||
(res->lit_pos_bits << 8) |
|
(res->lit_pos_bits << 8) |
|
||||||
(res->pos_bits << 16);
|
(res->pos_bits << 16);
|
||||||
if (linker->bele->isBE()) // big endian - bswap32
|
if (bele->isBE()) // big endian - bswap32
|
||||||
properties = bswap32(properties);
|
properties = bswap32(properties);
|
||||||
|
|
||||||
linker->defineSymbol("lzma_properties", properties);
|
linker->defineSymbol("lzma_properties", properties);
|
||||||
|
|||||||
Reference in New Issue
Block a user