mirror of
https://github.com/corda/corda.git
synced 2025-01-01 02:36:44 +00:00
clean up binary format code
Linux, FreeBSD, and QNX all use ELF, so no need to distinguish between them when generating object files. To avoid confusion, I've switch from using operating system names to using binary format names where applicable.
This commit is contained in:
parent
e641f23e6c
commit
f03e5e8e55
31
makefile
31
makefile
@ -24,7 +24,6 @@ target-arch = $(arch)
|
||||
bootimage-platform = \
|
||||
$(subst cygwin,windows,$(subst mingw32,windows,$(build-platform)))
|
||||
platform = $(bootimage-platform)
|
||||
target-platform = $(platform)
|
||||
|
||||
mode = fast
|
||||
process = compile
|
||||
@ -165,6 +164,8 @@ ifneq ($(platform),darwin)
|
||||
endif
|
||||
endif
|
||||
|
||||
target-format = elf
|
||||
|
||||
cxx = $(build-cxx) $(mflag)
|
||||
cc = $(build-cc) $(mflag)
|
||||
|
||||
@ -211,7 +212,7 @@ build-cflags = $(common-cflags) -fPIC -fvisibility=hidden \
|
||||
converter-cflags = -D__STDC_CONSTANT_MACROS -Isrc/binaryToObject -Isrc/ \
|
||||
-fno-rtti -fno-exceptions \
|
||||
-DAVIAN_TARGET_ARCH=AVIAN_ARCH_UNKNOWN \
|
||||
-DAVIAN_TARGET_PLATFORM=AVIAN_PLATFORM_UNKNOWN \
|
||||
-DAVIAN_TARGET_FORMAT=AVIAN_FORMAT_UNKNOWN \
|
||||
-Wall -Wextra -Werror -Wunused-parameter -Winit-self -Wno-non-virtual-dtor
|
||||
|
||||
cflags = $(build-cflags)
|
||||
@ -314,7 +315,6 @@ ifeq ($(build-platform),darwin)
|
||||
endif
|
||||
|
||||
ifeq ($(platform),qnx)
|
||||
target-platform = linux
|
||||
cflags = $(common-cflags) -fPIC -fvisibility=hidden -I$(src)
|
||||
lflags = $(common-lflags) -lsocket
|
||||
ifeq ($(build-platform),qnx)
|
||||
@ -346,6 +346,7 @@ ifeq ($(platform),freebsd)
|
||||
endif
|
||||
|
||||
ifeq ($(platform),darwin)
|
||||
target-format = macho
|
||||
ifeq (${OSX_SDK_SYSROOT},)
|
||||
OSX_SDK_SYSROOT = 10.4u
|
||||
endif
|
||||
@ -427,6 +428,8 @@ ifeq ($(platform),darwin)
|
||||
endif
|
||||
|
||||
ifeq ($(platform),windows)
|
||||
target-format = pe
|
||||
|
||||
inc = "$(win32)/include"
|
||||
lib = "$(win32)/lib"
|
||||
|
||||
@ -854,20 +857,16 @@ ifeq ($(target-arch),arm)
|
||||
cflags += -DAVIAN_TARGET_ARCH=AVIAN_ARCH_ARM
|
||||
endif
|
||||
|
||||
ifeq ($(target-platform),linux)
|
||||
cflags += -DAVIAN_TARGET_PLATFORM=AVIAN_PLATFORM_LINUX
|
||||
ifeq ($(target-format),elf)
|
||||
cflags += -DAVIAN_TARGET_FORMAT=AVIAN_FORMAT_ELF
|
||||
endif
|
||||
|
||||
ifeq ($(target-platform),windows)
|
||||
cflags += -DAVIAN_TARGET_PLATFORM=AVIAN_PLATFORM_WINDOWS
|
||||
ifeq ($(target-format),pe)
|
||||
cflags += -DAVIAN_TARGET_FORMAT=AVIAN_FORMAT_PE
|
||||
endif
|
||||
|
||||
ifeq ($(target-platform),darwin)
|
||||
cflags += -DAVIAN_TARGET_PLATFORM=AVIAN_PLATFORM_DARWIN
|
||||
endif
|
||||
|
||||
ifeq ($(target-platform),freebsd)
|
||||
cflags += -DAVIAN_TARGET_PLATFORM=AVIAN_PLATFORM_FREEBSD
|
||||
ifeq ($(target-format),macho)
|
||||
cflags += -DAVIAN_TARGET_FORMAT=AVIAN_FORMAT_MACHO
|
||||
endif
|
||||
|
||||
class-name = $(patsubst $(1)/%.class,%,$(2))
|
||||
@ -1050,7 +1049,7 @@ $(build)/classpath.jar: $(classpath-dep) $(classpath-jar-dep)
|
||||
$(classpath-object): $(build)/classpath.jar $(converter)
|
||||
@echo "creating $(@)"
|
||||
$(converter) $(<) $(@) _binary_classpath_jar_start \
|
||||
_binary_classpath_jar_end $(target-platform) $(arch)
|
||||
_binary_classpath_jar_end $(target-format) $(arch)
|
||||
|
||||
$(build)/javahome.jar:
|
||||
@echo "creating $(@)"
|
||||
@ -1061,7 +1060,7 @@ $(build)/javahome.jar:
|
||||
$(javahome-object): $(build)/javahome.jar $(converter)
|
||||
@echo "creating $(@)"
|
||||
$(converter) $(<) $(@) _binary_javahome_jar_start \
|
||||
_binary_javahome_jar_end $(target-platform) $(arch)
|
||||
_binary_javahome_jar_end $(target-format) $(arch)
|
||||
|
||||
define compile-generator-object
|
||||
@echo "compiling $(@)"
|
||||
@ -1122,7 +1121,7 @@ $(bootimage-generator): $(bootimage-generator-objects)
|
||||
arch=$(build-arch) \
|
||||
target-arch=$(arch) \
|
||||
platform=$(bootimage-platform) \
|
||||
target-platform=$(target-platform) \
|
||||
target-format=$(target-format) \
|
||||
openjdk=$(openjdk) \
|
||||
openjdk-src=$(openjdk-src) \
|
||||
bootimage-generator= \
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* arm.S: JNI gluecode for ARM/Linux
|
||||
/* arm.S: JNI gluecode for ARM
|
||||
Copyright (c) 2008-2011, Avian Contributors
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software
|
||||
|
@ -197,8 +197,8 @@ public:
|
||||
|
||||
const unsigned machine;
|
||||
|
||||
ElfPlatform(PlatformInfo::OperatingSystem os, PlatformInfo::Architecture arch):
|
||||
Platform(PlatformInfo(os, arch)),
|
||||
ElfPlatform(PlatformInfo::Architecture arch):
|
||||
Platform(PlatformInfo(PlatformInfo::Elf, arch)),
|
||||
machine(getElfPlatform(arch)) {}
|
||||
|
||||
class FileWriter {
|
||||
@ -372,15 +372,9 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
ElfPlatform<uint32_t> elfLinuxX86Platform(PlatformInfo::Linux, PlatformInfo::x86);
|
||||
ElfPlatform<uint32_t> elfLinuxArmPlatform(PlatformInfo::Linux, PlatformInfo::Arm);
|
||||
ElfPlatform<uint32_t, false> elfLinuxPowerPCPlatform(PlatformInfo::Linux, PlatformInfo::PowerPC);
|
||||
ElfPlatform<uint64_t> elfLinuxX86_64Platform(PlatformInfo::Linux, PlatformInfo::x86_64);
|
||||
|
||||
ElfPlatform<uint32_t> elfFreeBSDx86Platform(PlatformInfo::FreeBSD, PlatformInfo::x86);
|
||||
ElfPlatform<uint32_t> elfFreeBSDArmPlatform(PlatformInfo::FreeBSD, PlatformInfo::Arm);
|
||||
ElfPlatform<uint32_t, false> elfFreeBSDPowerPCPlatform(PlatformInfo::FreeBSD, PlatformInfo::PowerPC);
|
||||
ElfPlatform<uint64_t> elfFreeBSDx86_64Platform(PlatformInfo::FreeBSD, PlatformInfo::x86_64);
|
||||
|
||||
ElfPlatform<uint32_t> elfX86Platform(PlatformInfo::x86);
|
||||
ElfPlatform<uint32_t> elfArmPlatform(PlatformInfo::Arm);
|
||||
ElfPlatform<uint32_t, false> elfPowerPCPlatform(PlatformInfo::PowerPC);
|
||||
ElfPlatform<uint64_t> elfX86_64Platform(PlatformInfo::x86_64);
|
||||
|
||||
} // namespace
|
||||
|
@ -286,7 +286,7 @@ public:
|
||||
}
|
||||
|
||||
MachOPlatform(PlatformInfo::Architecture arch):
|
||||
Platform(PlatformInfo(PlatformInfo::Darwin, arch)) {}
|
||||
Platform(PlatformInfo(PlatformInfo::MachO, arch)) {}
|
||||
|
||||
};
|
||||
|
||||
|
@ -41,14 +41,14 @@ using namespace avian::tools;
|
||||
|
||||
bool
|
||||
writeObject(uint8_t* data, size_t size, OutputStream* out, const char* startName,
|
||||
const char* endName, const char* os,
|
||||
const char* endName, const char* format,
|
||||
const char* architecture, unsigned alignment, bool writable,
|
||||
bool executable)
|
||||
{
|
||||
Platform* platform = Platform::getPlatform(PlatformInfo(PlatformInfo::osFromString(os), PlatformInfo::archFromString(architecture)));
|
||||
Platform* platform = Platform::getPlatform(PlatformInfo(PlatformInfo::formatFromString(format), PlatformInfo::archFromString(architecture)));
|
||||
|
||||
if(!platform) {
|
||||
fprintf(stderr, "unsupported platform: %s/%s\n", os, architecture);
|
||||
fprintf(stderr, "unsupported platform: %s/%s\n", format, architecture);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -269,7 +269,7 @@ public:
|
||||
}
|
||||
|
||||
WindowsPlatform():
|
||||
Platform(PlatformInfo(PlatformInfo::Windows, BytesPerWord == 4 ? PlatformInfo::x86 : PlatformInfo::x86_64)) {}
|
||||
Platform(PlatformInfo(PlatformInfo::Pe, BytesPerWord == 4 ? PlatformInfo::x86 : PlatformInfo::x86_64)) {}
|
||||
};
|
||||
|
||||
WindowsPlatform<4> windows32Platform;
|
||||
|
@ -85,17 +85,23 @@ void FileOutputStream::write(uint8_t byte) {
|
||||
|
||||
Platform* Platform::first = 0;
|
||||
|
||||
PlatformInfo::OperatingSystem PlatformInfo::osFromString(const char* os) {
|
||||
if(strcmp(os, "linux") == 0) {
|
||||
return Linux;
|
||||
} else if(strcmp(os, "windows") == 0) {
|
||||
return Windows;
|
||||
} else if(strcmp(os, "darwin") == 0) {
|
||||
return Darwin;
|
||||
} else if(strcmp(os, "freebsd") == 0) {
|
||||
return FreeBSD;
|
||||
PlatformInfo::Format PlatformInfo::formatFromString(const char* format) {
|
||||
if (strcmp(format, "elf") == 0
|
||||
or strcmp(format, "linux") == 0
|
||||
or strcmp(format, "freebsd") == 0
|
||||
or strcmp(format, "qnx") == 0)
|
||||
{
|
||||
return Elf;
|
||||
} else if (strcmp(format, "pe") == 0
|
||||
or strcmp(format, "windows") == 0)
|
||||
{
|
||||
return Pe;
|
||||
} else if (strcmp(format, "macho") == 0
|
||||
or strcmp(format, "darwin") == 0)
|
||||
{
|
||||
return MachO;
|
||||
} else {
|
||||
return UnknownOS;
|
||||
return UnknownFormat;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -131,12 +131,11 @@ public:
|
||||
|
||||
class PlatformInfo {
|
||||
public:
|
||||
enum OperatingSystem {
|
||||
Linux = AVIAN_PLATFORM_LINUX,
|
||||
Windows = AVIAN_PLATFORM_WINDOWS,
|
||||
Darwin = AVIAN_PLATFORM_DARWIN,
|
||||
FreeBSD = AVIAN_PLATFORM_FREEBSD,
|
||||
UnknownOS = AVIAN_PLATFORM_UNKNOWN
|
||||
enum Format {
|
||||
Elf = AVIAN_FORMAT_ELF,
|
||||
Pe = AVIAN_FORMAT_PE,
|
||||
MachO = AVIAN_FORMAT_MACHO,
|
||||
UnknownFormat = AVIAN_FORMAT_UNKNOWN
|
||||
};
|
||||
|
||||
enum Architecture {
|
||||
@ -147,18 +146,18 @@ public:
|
||||
UnknownArch = AVIAN_ARCH_UNKNOWN
|
||||
};
|
||||
|
||||
const OperatingSystem os;
|
||||
const Format format;
|
||||
const Architecture arch;
|
||||
|
||||
static OperatingSystem osFromString(const char* os);
|
||||
static Format formatFromString(const char* format);
|
||||
static Architecture archFromString(const char* arch);
|
||||
|
||||
inline PlatformInfo(OperatingSystem os, Architecture arch):
|
||||
os(os),
|
||||
inline PlatformInfo(Format format, Architecture arch):
|
||||
format(format),
|
||||
arch(arch) {}
|
||||
|
||||
inline bool operator == (const PlatformInfo& other) {
|
||||
return os == other.os && arch == other.arch;
|
||||
return format == other.format && arch == other.arch;
|
||||
}
|
||||
|
||||
inline bool isLittleEndian() {
|
||||
|
@ -1647,7 +1647,7 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp
|
||||
|
||||
// fwrite(code, pad(image->codeSize, TargetBytesPerWord), 1, codeOutput);
|
||||
|
||||
Platform* platform = Platform::getPlatform(PlatformInfo((PlatformInfo::OperatingSystem)AVIAN_TARGET_PLATFORM, (PlatformInfo::Architecture)AVIAN_TARGET_ARCH));
|
||||
Platform* platform = Platform::getPlatform(PlatformInfo((PlatformInfo::Format)AVIAN_TARGET_FORMAT, (PlatformInfo::Architecture)AVIAN_TARGET_ARCH));
|
||||
|
||||
// if(!platform) {
|
||||
// fprintf(stderr, "unsupported platform: %s/%s\n", os, architecture);
|
||||
|
@ -11,19 +11,18 @@
|
||||
#ifndef AVIAN_ENVIRONMENT_H
|
||||
#define AVIAN_ENVIRONMENT_H
|
||||
|
||||
#ifndef AVIAN_TARGET_PLATFORM
|
||||
#error build system should have defined AVIAN_TARGET_PLATFORM
|
||||
#ifndef AVIAN_TARGET_FORMAT
|
||||
#error build system should have defined AVIAN_TARGET_FORMAT
|
||||
#endif
|
||||
|
||||
#ifndef AVIAN_TARGET_ARCH
|
||||
#error build system should have defined AVIAN_TARGET_ARCH
|
||||
#endif
|
||||
|
||||
#define AVIAN_PLATFORM_UNKNOWN 0
|
||||
#define AVIAN_PLATFORM_LINUX 1
|
||||
#define AVIAN_PLATFORM_WINDOWS 2
|
||||
#define AVIAN_PLATFORM_DARWIN 3
|
||||
#define AVIAN_PLATFORM_FREEBSD 4
|
||||
#define AVIAN_FORMAT_UNKNOWN 0
|
||||
#define AVIAN_FORMAT_ELF 1
|
||||
#define AVIAN_FORMAT_PE 2
|
||||
#define AVIAN_FORMAT_MACHO 3
|
||||
|
||||
#define AVIAN_ARCH_UNKNOWN 0
|
||||
#define AVIAN_ARCH_X86 (1 << 8)
|
||||
|
@ -2781,7 +2781,7 @@ class MyArchitecture: public Assembler::Architecture {
|
||||
}
|
||||
|
||||
virtual unsigned frameFootprint(unsigned footprint) {
|
||||
#if AVIAN_TARGET_PLATFORM == AVIAN_PLATFORM_WINDOWS
|
||||
#if AVIAN_TARGET_FORMAT == AVIAN_FORMAT_PE
|
||||
return max(footprint, StackAlignmentInWords);
|
||||
#else
|
||||
return max(footprint > argumentRegisterCount() ?
|
||||
@ -2803,7 +2803,7 @@ class MyArchitecture: public Assembler::Architecture {
|
||||
}
|
||||
|
||||
virtual unsigned argumentRegisterCount() {
|
||||
#if AVIAN_TARGET_PLATFORM == AVIAN_PLATFORM_WINDOWS
|
||||
#if AVIAN_TARGET_FORMAT == AVIAN_FORMAT_PE
|
||||
if (TargetBytesPerWord == 8) return 4; else
|
||||
#else
|
||||
if (TargetBytesPerWord == 8) return 6; else
|
||||
@ -2814,7 +2814,7 @@ class MyArchitecture: public Assembler::Architecture {
|
||||
virtual int argumentRegister(unsigned index) {
|
||||
assert(&c, TargetBytesPerWord == 8);
|
||||
switch (index) {
|
||||
#if AVIAN_TARGET_PLATFORM == AVIAN_PLATFORM_WINDOWS
|
||||
#if AVIAN_TARGET_FORMAT == AVIAN_FORMAT_PE
|
||||
case 0:
|
||||
return rcx;
|
||||
case 1:
|
||||
|
Loading…
Reference in New Issue
Block a user