src: cleanup linker.h

This commit is contained in:
Markus F.X.J. Oberhumer 2023-04-19 23:19:45 +02:00
parent 7f5b64c91a
commit d1ab85a1a6
5 changed files with 19 additions and 59 deletions

View File

@ -101,11 +101,7 @@ ElfLinker::Relocation::Relocation(const Section *s, unsigned o, const char *t, c
// ElfLinker
**************************************************************************/
ElfLinker::ElfLinker()
: 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(const N_BELE_RTP::AbstractPolicy *b) noexcept : bele(b) {}
ElfLinker::~ElfLinker() noexcept {
delete[] input;

View File

@ -25,8 +25,7 @@
<markus@oberhumer.com> <ezerotven+github@gmail.com>
*/
#ifndef __UPX_LINKER_H
#define __UPX_LINKER_H 1
#pragma once
/*************************************************************************
// ElfLinker
@ -36,7 +35,7 @@ class ElfLinker : private noncopyable {
friend class Packer;
public:
const N_BELE_RTP::AbstractPolicy *bele = nullptr; // target endianness
const N_BELE_RTP::AbstractPolicy *const bele; // target endianness
protected:
struct Section;
struct Symbol;
@ -76,7 +75,7 @@ protected:
const char *symbol, upx_uint64_t add);
public:
ElfLinker();
ElfLinker(const N_BELE_RTP::AbstractPolicy *b = &N_BELE_RTP::le_policy) noexcept;
virtual ~ElfLinker() noexcept;
void init(const void *pdata, int plen, unsigned pxtra = 0);
@ -113,14 +112,6 @@ protected:
void relocate();
virtual void relocate1(const Relocation *, byte *location, upx_uint64_t value,
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 {
@ -162,28 +153,23 @@ struct ElfLinker::Relocation : private noncopyable {
class ElfLinkerAMD64 : public ElfLinker {
typedef ElfLinker super;
protected:
virtual void alignCode(unsigned len) override { alignWithByte(len, 0x90); }
virtual void relocate1(const Relocation *, byte *location, upx_uint64_t value,
const char *type) override;
};
class ElfLinkerARM64 final : public ElfLinker {
class ElfLinkerArm64LE final : public ElfLinker {
typedef ElfLinker super;
protected:
virtual void alignCode(unsigned len) override { alignWithByte(len, 0x90); }
virtual void relocate1(const Relocation *, byte *location, upx_uint64_t value,
const char *type) override;
};
class ElfLinkerArmBE final : public ElfLinker {
typedef ElfLinker super;
public:
ElfLinkerArmBE() { bele = &N_BELE_RTP::be_policy; }
ElfLinkerArmBE() noexcept : super(&N_BELE_RTP::be_policy) {}
protected:
virtual void relocate1(const Relocation *, byte *location, upx_uint64_t value,
const char *type) override;
@ -191,15 +177,6 @@ protected:
class ElfLinkerArmLE final : public ElfLinker {
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:
virtual void relocate1(const Relocation *, byte *location, upx_uint64_t value,
const char *type) override;
@ -207,10 +184,8 @@ protected:
class ElfLinkerM68k final : public ElfLinker {
typedef ElfLinker super;
public:
ElfLinkerM68k() { bele = &N_BELE_RTP::be_policy; }
ElfLinkerM68k() noexcept : super(&N_BELE_RTP::be_policy) {}
protected:
virtual void alignCode(unsigned len) override;
virtual void relocate1(const Relocation *, byte *location, upx_uint64_t value,
@ -219,10 +194,8 @@ protected:
class ElfLinkerMipsBE final : public ElfLinker {
typedef ElfLinker super;
public:
ElfLinkerMipsBE() { bele = &N_BELE_RTP::be_policy; }
ElfLinkerMipsBE() noexcept : super(&N_BELE_RTP::be_policy) {}
protected:
virtual void relocate1(const Relocation *, byte *location, upx_uint64_t value,
const char *type) override;
@ -230,7 +203,6 @@ protected:
class ElfLinkerMipsLE final : public ElfLinker {
typedef ElfLinker super;
protected:
virtual void relocate1(const Relocation *, byte *location, upx_uint64_t value,
const char *type) override;
@ -238,18 +210,8 @@ protected:
class ElfLinkerPpc32 final : public ElfLinker {
typedef ElfLinker super;
public:
ElfLinkerPpc32() { bele = &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;
ElfLinkerPpc32() noexcept : super(&N_BELE_RTP::be_policy) {}
protected:
virtual void relocate1(const Relocation *, byte *location, upx_uint64_t value,
const char *type) override;
@ -257,10 +219,15 @@ protected:
class ElfLinkerPpc64 final : public ElfLinker {
typedef ElfLinker super;
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:
virtual void relocate1(const Relocation *, byte *location, upx_uint64_t value,
const char *type) override;
@ -268,13 +235,10 @@ protected:
class ElfLinkerX86 final : public ElfLinker {
typedef ElfLinker super;
protected:
virtual void alignCode(unsigned len) override { alignWithByte(len, 0x90); }
virtual void relocate1(const Relocation *, byte *location, upx_uint64_t value,
const char *type) override;
};
#endif /* already included */
/* vim:set ts=4 sw=4 et: */

View File

@ -379,7 +379,7 @@ PackLinuxI386::buildLinuxLoader(
(res->lit_context_bits << 0) |
(res->lit_pos_bits << 8) |
(res->pos_bits << 16);
if (linker->bele->isBE()) // big endian - bswap32
if (bele->isBE()) // big endian - bswap32
properties = bswap32(properties);
linker->defineSymbol("lzma_properties", properties);
// -2 for properties

View File

@ -595,7 +595,7 @@ void PackBvmlinuzI386::pack(OutputFile *fo)
(res->lit_context_bits << 0) |
(res->lit_pos_bits << 8) |
(res->pos_bits << 16);
if (linker->bele->isBE()) // big endian - bswap32
if (bele->isBE()) // big endian - bswap32
properties = bswap32(properties);
linker->defineSymbol("lzma_properties", properties);
// -2 for properties

View File

@ -257,7 +257,7 @@ void Packer::defineDecompressorSymbols()
(res->lit_context_bits << 0) |
(res->lit_pos_bits << 8) |
(res->pos_bits << 16);
if (linker->bele->isBE()) // big endian - bswap32
if (bele->isBE()) // big endian - bswap32
properties = bswap32(properties);
linker->defineSymbol("lzma_properties", properties);