Small cleanups.

This commit is contained in:
Markus F.X.J. Oberhumer
2014-01-07 23:03:16 +01:00
parent 4a87834e04
commit 7db3e98944
2 changed files with 19 additions and 14 deletions
+1 -3
View File
@@ -336,9 +336,7 @@ typedef acc_uintptr_t upx_uintptr_t;
#endif #endif
#if (ACC_CC_INTELC && (__INTEL_COMPILER < 800)) #if (ACC_CC_CLANG || ACC_CC_GNUC || (ACC_CC_INTELC_GNUC && (__INTEL_COMPILER >= 800)) || ACC_CC_PATHSCALE)
#elif (0 && (ACC_ARCH_AMD64 || ACC_ARCH_I386))
#elif (ACC_CC_CLANG || ACC_CC_GNUC || ACC_CC_INTELC_GNUC || ACC_CC_PATHSCALE)
# define __packed_struct(s) struct s { # define __packed_struct(s) struct s {
# define __packed_struct_end() } __attribute__((__packed__,__aligned__(1))); # define __packed_struct_end() } __attribute__((__packed__,__aligned__(1)));
#elif (ACC_CC_WATCOMC) #elif (ACC_CC_WATCOMC)
+18 -11
View File
@@ -243,12 +243,12 @@ class ImportLinker : public ElfLinkerAMD64
unsigned len = 1 + 2 * strlen(dll) + 1 + 2 * strlen(proc) + 1 + 1; unsigned len = 1 + 2 * strlen(dll) + 1 + 2 * strlen(proc) + 1 + 1;
tstr dlln(name_for_dll(dll, first_char)); tstr dlln(name_for_dll(dll, first_char));
char *procn = new char[len]; char *procn = new char[len];
snprintf(procn, len - 1, "%s%c", (const char*) dlln, separator); upx_snprintf(procn, len - 1, "%s%c", (const char*) dlln, separator);
encode_name(proc, procn + strlen(procn)); encode_name(proc, procn + strlen(procn));
return procn; return procn;
} }
static char zeros[sizeof(import_desc)]; static const char zeros[sizeof(import_desc)];
enum { enum {
// the order of identifiers is very important below!! // the order of identifiers is very important below!!
@@ -347,15 +347,18 @@ public:
template <typename C> template <typename C>
void add(const C *dll, unsigned ordinal) void add(const C *dll, unsigned ordinal)
{ {
ACC_COMPILE_TIME_ASSERT(sizeof(C) == 1) // "char" or "unsigned char"
assert(ordinal > 0 && ordinal < 0x10000); assert(ordinal > 0 && ordinal < 0x10000);
char ord[20]; char ord[1+5+1];
snprintf(ord, sizeof(ord), "%c%05u", ordinal_id, ordinal); upx_snprintf(ord, sizeof(ord), "%c%05u", ordinal_id, ordinal);
add((const char*) dll, ord, ordinal); add((const char*) dll, ord, ordinal);
} }
template <typename C1, typename C2> template <typename C1, typename C2>
void add(const C1 *dll, const C2 *proc) void add(const C1 *dll, const C2 *proc)
{ {
ACC_COMPILE_TIME_ASSERT(sizeof(C1) == 1) // "char" or "unsigned char"
ACC_COMPILE_TIME_ASSERT(sizeof(C2) == 1) // "char" or "unsigned char"
assert(proc); assert(proc);
add((const char*) dll, (const char*) proc, 0); add((const char*) dll, (const char*) proc, 0);
} }
@@ -392,6 +395,8 @@ public:
template <typename C1, typename C2> template <typename C1, typename C2>
upx_uint64_t getAddress(const C1 *dll, const C2 *proc) const upx_uint64_t getAddress(const C1 *dll, const C2 *proc) const
{ {
ACC_COMPILE_TIME_ASSERT(sizeof(C1) == 1) // "char" or "unsigned char"
ACC_COMPILE_TIME_ASSERT(sizeof(C2) == 1) // "char" or "unsigned char"
const Section *s = getThunk((const char*) dll, (const char*) proc, const Section *s = getThunk((const char*) dll, (const char*) proc,
thunk_separator_first); thunk_separator_first);
if (s == NULL && (s = getThunk((const char*) dll,(const char*) proc, if (s == NULL && (s = getThunk((const char*) dll,(const char*) proc,
@@ -400,12 +405,13 @@ public:
return s->offset; return s->offset;
} }
template <typename C1> template <typename C>
upx_uint64_t getAddress(const C1 *dll, unsigned ordinal) const upx_uint64_t getAddress(const C *dll, unsigned ordinal) const
{ {
ACC_COMPILE_TIME_ASSERT(sizeof(C) == 1) // "char" or "unsigned char"
assert(ordinal > 0 && ordinal < 0x10000); assert(ordinal > 0 && ordinal < 0x10000);
char ord[20]; char ord[1+5+1];
snprintf(ord, sizeof(ord), "%c%05u", ordinal_id, ordinal); upx_snprintf(ord, sizeof(ord), "%c%05u", ordinal_id, ordinal);
const Section *s = getThunk((const char*) dll, ord, thunk_separator_first); const Section *s = getThunk((const char*) dll, ord, thunk_separator_first);
if (s == NULL if (s == NULL
@@ -414,14 +420,15 @@ public:
return s->offset; return s->offset;
} }
template <typename C1> template <typename C>
upx_uint64_t getAddress(const C1 *dll) const upx_uint64_t getAddress(const C *dll) const
{ {
ACC_COMPILE_TIME_ASSERT(sizeof(C) == 1) // "char" or "unsigned char"
tstr sdll(name_for_dll((const char*) dll, dll_name_id)); tstr sdll(name_for_dll((const char*) dll, dll_name_id));
return findSection(sdll, true)->offset; return findSection(sdll, true)->offset;
} }
}; };
char ImportLinker::zeros[sizeof(import_desc)]; const char ImportLinker::zeros[sizeof(import_desc)] = { 0 };
ImportLinker ilinker(8); ImportLinker ilinker(8);