Merge pull request #37 from gmbr3/v4_0

Add macOS support
This commit is contained in:
Nigel Croxon 2024-07-15 07:37:24 -04:00 committed by GitHub
commit feddb5ad3c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 188 additions and 8 deletions

104
.github/workflows/macos-gcc.yml vendored Normal file
View File

@ -0,0 +1,104 @@
name: macOS, gcc
on: [push, pull_request]
jobs:
build:
runs-on: macos-latest
strategy:
matrix:
arch: [x64, aa64]
include:
- arch: x64
dir: x86_64
cross_compile: x86_64-elf-
toolchain: x86_64-elf-gcc
- arch: aa64
dir: aarch64
cross_compile: aarch64-elf-
toolchain: aarch64-elf-gcc
steps:
- name: Install toolchain
run: |
brew install ${{ matrix.toolchain }}
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Build
run: |
make ARCH=${{ matrix.arch }} CROSS_COMPILE=${{ matrix.cross_compile }} USING_APPLE=1
- name: Generate binary information
run: ${{ matrix.cross_compile }}readelf -a ./${{ matrix.dir }}/apps/ctors_dtors_priority_test.so > ./${{ matrix.dir }}/apps/readelf.txt
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.arch }}
path: |
./${{ matrix.dir }}/apps/*
tests:
runs-on: ubuntu-24.04
needs: build
strategy:
matrix:
arch: [x64, aa64]
include:
- arch: x64
pkg: qemu-system-x86
qemu_arch: x86_64
qemu_opts: -M q35
fw_base: OVMF
- arch: aa64
pkg: qemu-system-arm
qemu_arch: aarch64
qemu_opts: -M virt -cpu cortex-a57
fw_base: AAVMF
steps:
- name: Set up Linux environment
run: |
sudo apt-get update
sudo apt-get -y --no-install-recommends install ${{ matrix.pkg }}
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: ${{ matrix.arch }}
- name: Download UEFI firmware
run: |
fw_arch=$(echo ${{ matrix.arch }} | tr a-z A-Z)
fw_zip=${{ matrix.fw_base }}-${fw_arch}.zip
curl -O https://efi.akeo.ie/${{ matrix.fw_base }}/${fw_zip}
7z x ${fw_zip}
rm ${fw_zip}
- name: Download UEFI Shell
run: |
curl -L -O https://github.com/pbatard/UEFI-Shell/releases/download/23H2/UEFI-Shell-2.2-23H2-RELEASE.iso
mkdir ./image
7z x -o./image *.iso
rm *.iso
- name: Run tests
run: |
export UEFI_ARCH=${{ matrix.arch }}
export UEFI_DIR=./image
export QEMU_CMD="qemu-system-${{ matrix.qemu_arch }} ${{ matrix.qemu_opts }} -nodefaults -nographic -serial stdio -net none -L . -drive if=pflash,format=raw,unit=0,file=${{ matrix.fw_base }}.fd,readonly=on -drive format=raw,file=fat:rw:image"
./tests/gen_tests.sh ./tests/test_list.txt
./tests/run_tests.sh

View File

@ -110,6 +110,7 @@ endif
GCCVERSION := $(shell $(CC) -dumpversion | sed -e 's/-win32/.0/' | cut -f1 -d.)
GCCMINOR := $(shell $(CC) -dumpversion | sed -e 's/-win32/.0/' | cut -f2 -d.)
USING_CLANG := $(shell $(CC) -v 2>&1 | grep -q 'clang version' && echo clang || echo 0)
USING_APPLE ?= 0
# Rely on GCC MS ABI support?
GCCNEWENOUGH := $(shell ( [ $(GCCVERSION) -gt "4" ] \
@ -212,6 +213,9 @@ export SYSTEM_HAS_EFI_OBJCOPY ?= 0
endif
ifeq ($(USING_APPLE),1)
CFLAGS += -D__GNU_EFI_IS_APPLE
endif
ifeq ($(ARCH),arm)
CFLAGS += -marm
@ -260,7 +264,10 @@ ASFLAGS += $(ARCH3264)
LDFLAGS += -nostdlib
ifeq ($(IS_MINGW32),)
LDFLAGS += --warn-common --no-undefined --fatal-warnings \
--build-id=sha1 -z nocombreloc -z norelro
--build-id=sha1 -z nocombreloc
ifeq ($(USING_APPLE),0)
LDFLAGS += -z norelro
endif
else
LDFLAGS += -Wl,--warn-common -Wl,--no-undefined -Wl,--fatal-warnings \
-Wl,--build-id=sha1

View File

@ -37,7 +37,7 @@
#include <efi.h>
#include <efilib.h>
#include <elf.h>
#include "subst/elf.h"
EFI_STATUS _relocate (long ldbase, Elf64_Dyn *dyn,
EFI_HANDLE image EFI_UNUSED,

View File

@ -37,7 +37,7 @@
#include <efi.h>
#include <efilib.h>
#include <elf.h>
#include "subst/elf.h"
EFI_STATUS _relocate (long ldbase, Elf32_Dyn *dyn,
EFI_HANDLE image EFI_UNUSED,

View File

@ -36,7 +36,7 @@
#include <efi.h>
#include <efilib.h>
#include <elf.h>
#include "subst/elf.h"
EFI_STATUS _relocate (long ldbase, Elf32_Dyn *dyn,
EFI_HANDLE image EFI_UNUSED,

View File

@ -38,7 +38,7 @@
#include <efi.h>
#include <efilib.h>
#include <elf.h>
#include "subst/elf.h"
EFI_STATUS _relocate (long ldbase, Elf64_Dyn *dyn,
EFI_HANDLE image EFI_UNUSED,

View File

@ -39,7 +39,7 @@
#include <efi.h>
#include <efilib.h>
#include <elf.h>
#include "subst/elf.h"
EFI_STATUS _relocate (long ldbase, Elf64_Dyn *dyn,
EFI_HANDLE image EFI_UNUSED,

View File

@ -38,7 +38,7 @@
#include <efi.h>
#include <elf.h>
#include "subst/elf.h"
#define Elf_Dyn Elf64_Dyn
#define Elf_Rela Elf64_Rela

View File

@ -38,7 +38,7 @@
#include <efi.h>
#include <efilib.h>
#include <elf.h>
#include "subst/elf.h"
EFI_STATUS _relocate (long ldbase, Elf64_Dyn *dyn,
EFI_HANDLE image EFI_UNUSED,

69
inc/subst/elf.h Normal file
View File

@ -0,0 +1,69 @@
#if !defined(__APPLE__) && !defined(__GNU_EFI_IS_APPLE)
#include <elf.h>
#else
typedef uint32_t Elf32_Addr;
typedef int32_t Elf32_Sword;
typedef uint32_t Elf32_Word;
typedef uint64_t Elf64_Addr;
typedef int64_t Elf64_Sxword;
typedef uint64_t Elf64_Xword;
typedef struct {
Elf32_Addr r_offset;
uint32_t r_info;
} Elf32_Rel;
typedef struct {
Elf64_Addr r_offset;
uint64_t r_info;
int64_t r_addend;
} Elf64_Rela;
typedef struct {
Elf32_Sword d_tag;
union {
Elf32_Word d_val;
Elf32_Addr d_ptr;
} d_un;
} Elf32_Dyn;
typedef struct {
Elf64_Sxword d_tag;
union {
Elf64_Xword d_val;
Elf64_Addr d_ptr;
} d_un;
} Elf64_Dyn;
#define ELF32_R_TYPE(val) ((val) & 0xff)
#define ELF64_R_TYPE(i) ((i) & 0xffffffff)
#define DT_NULL 0
#define DT_RELA 7
#define DT_RELASZ 8
#define DT_RELAENT 9
#define DT_PLTGOT 3
#define R_AARCH64_NONE 0
#define R_AARCH64_RELATIVE 1027
#define R_RISCV_RELATIVE 3
#define R_LARCH_NONE 0
#define R_LARCH_RELATIVE 3
#define R_X86_64_NONE 0
#define R_X86_64_RELATIVE 8
#define R_ARM_NONE 0
#define R_ARM_RELATIVE 23
#define R_386_NONE 0
#define R_386_RELATIVE 8
#define R_MIPS_NONE 0
#define R_MIPS_64 18
#define R_MIPS_REL32 3
#endif