Add substitute elf.h for macOS

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
This commit is contained in:
Callum Farmer 2024-07-14 17:35:36 +01:00
parent f19216bf87
commit b6f99c7ac5
No known key found for this signature in database
GPG Key ID: 9A5B19E18CD0013C
9 changed files with 80 additions and 7 deletions

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

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