aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchandramouli narayanan <mouli@linux.intel.com>2012-06-25 12:45:26 -0700
committerchandramouli narayanan <mouli@linux.intel.com>2012-06-25 12:45:26 -0700
commit38e58635d3868c23537fc5dce87b152a52df34ad (patch)
treef5677ef70b952068e8ebcd0f20daf06f50f8c178
parentd8eede3f2a360163235fad222a0190cd7c5bef38 (diff)
downloadsyslinux-38e58635d3868c23537fc5dce87b152a52df34ad.tar.gz
syslinux-38e58635d3868c23537fc5dce87b152a52df34ad.tar.xz
syslinux-38e58635d3868c23537fc5dce87b152a52df34ad.zip
The make files have undergone changes to support both i386 and x86_64 platforms.
Pertinent changes are sprinkled through *.mk and Makefile in the syslinux tree. Build architecture is specified at the command line via ARCH macro. This is to enable whether one is building for the native platform or cross-building for a different architecture. Currently, the only supported architectures via ARCH macro are i386 and x86_64. There are some modules (e.g. memdump) that don't build under the EFI environment. To go forward with efi boot support, a separate EFI_BUILD=1 macro has been added and is required to be specified while building. This is a temporary solution for the current build environment. example build: On a x86_64 platform, the following cross-builds syslinux for i386 To build for i386: make EFI_BUILD=1 ARCH=i386 On a x86_64 platform, the following builds syslinux for x86_64 To build natively: make EFI_BUILD=1 Changes specific to GCC and LD options: Architecture specific flags and include/search directories are set up for GCC and LD commands. Internally, GCC options such as stack-boundary, PIC and machine architecture are set up based on ARCH macro. While stack-boundary=2 is fine for i386, it does not work for x86_64 and so it is left to the default value. Using -fPIE with gcc does not work with ld on x86_64, but -fPIC works fine. Similarly, target and elf options are set up for linking as approrpriate for architecture. Assumption about gnu-efi install path: Since the EFI build supports both EFI32 and EFI64, the following assumptions are made with regard to the installed location of gnu-efi on the build platform. 1. gnu-efi-ia32: assumed installed in /usr/local [ EFI-32 include files in /usr/local/include/efi and gnu-efi library in /usr/local/lib/ ] 2. gnu-efi-x86_64: assumed installed in /usr [ EFI-64 include files in /usr/include/efi and gnu-efi library in /usr/lib64/ ] Remanants of the unused old i386-only files, if any, need to be pruned.
-rw-r--r--Makefile16
-rw-r--r--com32/gfxboot/Makefile10
-rw-r--r--core/Makefile22
-rw-r--r--diag/mbr/Makefile2
-rw-r--r--gpxe/Makefile4
-rw-r--r--mbr/Makefile5
-rw-r--r--memdisk/Makefile3
-rw-r--r--mk/com32.mk38
-rw-r--r--mk/efi.mk47
-rw-r--r--mk/elf.mk29
-rw-r--r--mk/embedded.mk27
-rw-r--r--mk/lib.mk40
-rw-r--r--mk/syslinux.mk6
13 files changed, 196 insertions, 53 deletions
diff --git a/Makefile b/Makefile
index 0e799101..45d0b193 100644
--- a/Makefile
+++ b/Makefile
@@ -31,10 +31,19 @@ include $(MAKEDIR)/syslinux.mk
#
# List of module objects that should be installed for all derivatives
+ifndef EFI_BUILD
MODULES = memdisk/memdisk memdump/memdump.com modules/*.com \
com32/menu/*.c32 com32/modules/*.c32 com32/mboot/*.c32 \
com32/hdt/*.c32 com32/rosh/*.c32 com32/gfxboot/*.c32 \
com32/sysdump/*.c32 com32/lua/src/*.c32
+else
+# memdump is BIOS specific code exclude it for EFI
+# FIXME: Prune other BIOS-centric modules
+MODULES = memdisk/memdisk modules/*.com \
+ com32/menu/*.c32 com32/modules/*.c32 com32/mboot/*.c32 \
+ com32/hdt/*.c32 com32/rosh/*.c32 com32/gfxboot/*.c32 \
+ com32/sysdump/*.c32 com32/lua/src/*.c32
+endif
# syslinux.exe is BTARGET so as to not require everyone to have the
# mingw suite installed
@@ -53,8 +62,15 @@ BOBJECTS = $(BTARGET) \
# Note: libinstaller is both a BSUBDIR and an ISUBDIR. It contains
# files that depend only on the B phase, but may have to be regenerated
# for "make installer".
+ifndef EFI_BUILD
BSUBDIRS = codepage com32 lzo core memdisk modules mbr memdump gpxe sample \
diag libinstaller dos win32 win64 dosutil efi
+else
+# memdump is BIOS specific code exclude it for EFI
+# FIXME: Prune other BIOS-centric modules
+BSUBDIRS = codepage com32 lzo core memdisk modules mbr gpxe sample \
+ diag libinstaller win32 win64 dosutil efi
+endif
ITARGET =
IOBJECTS = $(ITARGET) \
utils/gethostip utils/isohybrid utils/mkdiskimage \
diff --git a/com32/gfxboot/Makefile b/com32/gfxboot/Makefile
index f2a73762..a2420c42 100644
--- a/com32/gfxboot/Makefile
+++ b/com32/gfxboot/Makefile
@@ -23,12 +23,22 @@ gfxboot.c32 : gfxboot.o realmode_callback.o $(LIBS) $(C_LIBS)
$(LD) $(LDFLAGS) -o $@ $^
realmode_callback.o: realmode_callback.asm
+ifeq ($(ARCH),i386)
$(NASM) -f bin -O99 -o $*.tmp -l $*.lst $<
$(OBJCOPY) -B i386 -I binary -O elf32-i386 \
--redefine-sym _binary_$*_tmp_start=$*_start \
--redefine-sym _binary_$*_tmp_end=$*_end \
--strip-symbol _binary_$*_tmp_size \
$*.tmp $@
+endif
+ifeq ($(ARCH),x86_64)
+ $(NASM) -f bin -O99 -o $*.tmp -l $*.lst $<
+ $(OBJCOPY) -B i386:x86-64 -I binary -O elf64-x86-64 \
+ --redefine-sym _binary_$*_tmp_start=$*_start \
+ --redefine-sym _binary_$*_tmp_end=$*_end \
+ --strip-symbol _binary_$*_tmp_size \
+ $*.tmp $@
+endif
tidy dist:
rm -f *.o *.lo *.a *.lst .*.d *.tmp
diff --git a/core/Makefile b/core/Makefile
index c55a12a3..fd8edd14 100644
--- a/core/Makefile
+++ b/core/Makefile
@@ -25,7 +25,7 @@ include $(MAKEDIR)/embedded.mk
-include $(topdir)/version.mk
OPTFLAGS =
-INCLUDES = -I./include -I$(com32)/include -I$(com32)/lib
+INCLUDES = -I./include -I$(com32)/include -I$(com32)/include/sys -I$(com32)/lib
# This is very similar to cp437; technically it's for Norway and Denmark,
# but it's unlikely the characters that are different will be used in
@@ -74,6 +74,19 @@ ifndef DATE
DATE := $(shell sh ../gen-id.sh $(VERSION) $(HEXDATE))
endif
+# Set up the NASM and LD options for the architecture
+NASM_ELF = "unknown"
+LD_PIE = "unknown"
+ifeq ($(ARCH),i386)
+ NASM_ELF = elf
+ LD_PIE = -pie
+endif
+ifeq ($(ARCH),x86_64)
+ NASM_ELF = elf64
+ #LD_PIE = --pic-executable
+ LD_PIE =
+endif
+
all: $(BTARGET) clean
kwdhash.gen: keywords genhash.pl
@@ -91,14 +104,15 @@ kwdhash.gen: keywords genhash.pl
$(PREPCORE) $< $@
%.o: %.asm kwdhash.gen ../version.gen
- $(NASM) -f elf $(NASMOPT) -DDATE_STR="'$(DATE)'" \
+ $(NASM) -f $(NASM_ELF) $(NASMOPT) -DDATE_STR="'$(DATE)'" \
-DHEXDATE="$(HEXDATE)" \
+ -D$(ARCH) \
-l $(@:.o=.lsr) -o $@ -MP -MD .$@.d $<
AUXLIBS = libisolinux.a libisolinux-debug.a libldlinux.a libpxelinux.a
-%.elf: %.o $(LIBDEP) syslinux.ld $(AUXLIBS)
- $(LD) $(LDFLAGS) -Bsymbolic -pie -E --hash-style=gnu -T syslinux.ld -M -o $@ $< \
+%.elf: %.o $(LIBDEP) $(ARCH)/syslinux.ld $(AUXLIBS)
+ $(LD) $(LDFLAGS) -Bsymbolic $(LD_PIE) -E --hash-style=gnu -T $(ARCH)/syslinux.ld -M -o $@ $< \
--start-group $(LIBS) lib$(patsubst %.elf,%.a,$@) --end-group \
> $(@:.elf=.map)
$(OBJDUMP) -h $@ > $(@:.elf=.sec)
diff --git a/diag/mbr/Makefile b/diag/mbr/Makefile
index 79ff9f01..f8582053 100644
--- a/diag/mbr/Makefile
+++ b/diag/mbr/Makefile
@@ -27,7 +27,7 @@ all: handoff.bin
.PRECIOUS: %.elf
%.elf: %.o $(mbrdir)/mbr.ld
- $(LD) $(LDFLAGS) -T $(mbrdir)/mbr.ld -e _start -o $@ $<
+ $(LD) $(LDFLAGS) -T $(mbrdir)/$(ARCH)/mbr.ld -e _start -o $@ $<
%.bin: %.elf $(mbrdir)/checksize.pl
$(OBJCOPY) -O binary $< $@
diff --git a/gpxe/Makefile b/gpxe/Makefile
index 8bce8d12..fe754c62 100644
--- a/gpxe/Makefile
+++ b/gpxe/Makefile
@@ -30,7 +30,9 @@ clean: tidy
dist:
$(MAKE) -C src veryclean > /dev/null 2>&1
-spotless: clean dist
+#spotless: clean dist
+#Including 'dist' errors out for make ARCH=x86_64 spotless
+spotless: clean
rm -f $(TARGETS)
installer:
diff --git a/mbr/Makefile b/mbr/Makefile
index 993bb100..8b46452a 100644
--- a/mbr/Makefile
+++ b/mbr/Makefile
@@ -33,8 +33,9 @@ all: mbr.bin altmbr.bin gptmbr.bin isohdpfx.bin isohdppx.bin \
$(CC) $(MAKEDEPS) $(SFLAGS) -Wa,-a=$*_f.lst -DFORCE_80 -c -o $@ $<
.PRECIOUS: %.elf
-%.elf: %.o mbr.ld
- $(LD) $(LDFLAGS) -T mbr.ld -e _start -o $@ $<
+#%.elf: %.o mbr.ld
+%.elf: %.o $(ARCH)/mbr.ld
+ $(LD) $(LDFLAGS) -T $(ARCH)/mbr.ld -e _start -o $@ $<
%.bin: %.elf checksize.pl
$(OBJCOPY) -O binary $< $@
diff --git a/memdisk/Makefile b/memdisk/Makefile
index 5475b44d..286ea405 100644
--- a/memdisk/Makefile
+++ b/memdisk/Makefile
@@ -84,7 +84,8 @@ memdisk_%.o: memdisk_%.bin
memdisk16.elf: $(OBJS16)
$(LD) -Ttext 0 -o $@ $^
-memdisk32.elf: memdisk.ld $(OBJS32)
+#memdisk32.elf: memdisk.ld $(OBJS32)
+memdisk32.elf: $(ARCH)/memdisk.ld $(OBJS32)
$(LD) -o $@ -T $^
%.bin: %.elf
diff --git a/mk/com32.mk b/mk/com32.mk
index db716c0d..32973407 100644
--- a/mk/com32.mk
+++ b/mk/com32.mk
@@ -17,13 +17,29 @@
include $(MAKEDIR)/syslinux.mk
+# Support IA32 and x86_64 platforms with one build
+# Set up architecture specifics; for cross compilation, set ARCH as apt
GCCOPT := $(call gcc_ok,-std=gnu99,)
-GCCOPT += $(call gcc_ok,-m32,)
+ifeq ($(strip $(ARCH)),i386)
+ GCCOPT += $(call gcc_ok,-m32,)
+ GCCOPT += $(call gcc_ok,-march=i386)
+ GCCOPT += $(call gcc_ok,-mpreferred-stack-boundary=2,)
+ GCCOPT += $(call gcc_ok,-incoming-stack-boundary=2,)
+endif
+ifeq ($(strip $(ARCH)),x86_64)
+ GCCOPT += $(call gcc_ok,-m64,)
+ GCCOPT += $(call gcc_ok,-march=x86-64)
+ #let the stack-boundary default to whatever it is on 64bit
+ #GCCOPT += $(call gcc_ok,-mpreferred-stack-boundary=8,)
+ #GCCOPT += $(call gcc_ok,-incoming-stack-boundary=8,)
+endif
GCCOPT += $(call gcc_ok,-fno-stack-protector,)
GCCOPT += $(call gcc_ok,-fwrapv,)
GCCOPT += $(call gcc_ok,-freg-struct-return,)
-GCCOPT += -march=i386 -Os
-GCCOPT += $(call gcc_ok,-fPIE,-fPIC)
+GCCOPT += -Os
+# Note -fPIE does not work with ld on x86_64, try -fPIC instead
+# Does BIOS build require -fPIE?
+GCCOPT += $(call gcc_ok,-fPIC)
GCCOPT += $(call gcc_ok,-fno-exceptions,)
GCCOPT += $(call gcc_ok,-fno-asynchronous-unwind-tables,)
GCCOPT += $(call gcc_ok,-fno-strict-aliasing,)
@@ -31,8 +47,6 @@ GCCOPT += $(call gcc_ok,-falign-functions=0,-malign-functions=0)
GCCOPT += $(call gcc_ok,-falign-jumps=0,-malign-jumps=0)
GCCOPT += $(call gcc_ok,-falign-labels=0,-malign-labels=0)
GCCOPT += $(call gcc_ok,-falign-loops=0,-malign-loops=0)
-GCCOPT += $(call gcc_ok,-mpreferred-stack-boundary=2,)
-GCCOPT += $(call gcc_ok,-incoming-stack-boundary=2,)
com32 := $(topdir)/com32
RELOCS := $(com32)/tools/relocs
@@ -45,17 +59,19 @@ GPLLIB =
GPLINCLUDE =
endif
-CFLAGS = $(GCCOPT) $(GCCWARN) -march=i386 \
+CFLAGS = $(GCCOPT) $(GCCWARN) \
-fomit-frame-pointer -D__COM32__ \
-nostdinc -iwithprefix include \
- -I$(com32)/libutil/include -I$(com32)/include $(GPLINCLUDE)
-SFLAGS = $(GCCOPT) $(GCCWARN) -march=i386 \
+ -I$(com32)/libutil/include -I$(com32)/include \
+ -I$(com32)/include/sys $(GPLINCLUDE)
+SFLAGS = $(GCCOPT) $(GCCWARN) \
-fomit-frame-pointer -D__COM32__ \
-nostdinc -iwithprefix include \
- -I$(com32)/libutil/include -I$(com32)/include $(GPLINCLUDE)
+ -I$(com32)/libutil/include -I$(com32)/include \
+ -I$(com32)/include/sys $(GPLINCLUDE)
-COM32LD = $(com32)/lib/elf32.ld
-LDFLAGS = -m elf_i386 -shared --hash-style=gnu -T $(COM32LD)
+COM32LD = $(com32)/lib/$(ARCH)/elf.ld
+LDFLAGS = -m elf_$(ARCH) -shared --hash-style=gnu -T $(COM32LD)
LIBGCC := $(shell $(CC) $(GCCOPT) --print-libgcc)
LNXCFLAGS = -I$(com32)/libutil/include $(GCCWARN) -O -g \
diff --git a/mk/efi.mk b/mk/efi.mk
index e4614481..ede87d91 100644
--- a/mk/efi.mk
+++ b/mk/efi.mk
@@ -3,26 +3,49 @@ include $(MAKEDIR)/syslinux.mk
com32 = $(topdir)/com32
core = $(topdir)/core
-ARCH=ia32
-LIBDIR=/usr/lib
-FORMAT=efi-app-$(ARCH)
-
-CFLAGS = -I/usr/include/efi -I/usr/include/efi/$(ARCH) \
+# Support IA32 and x86_64 platforms with one build
+# Set up architecture specifics; for cross compilation, set ARCH as apt
+# gnuefi sets up architecture specifics in ia32 or x86_64 sub directories
+# set up the LIBDIR and EFIINC for building for the appropriate architecture
+# For now, the following assumptions are made:
+# 1. gnu-efi lib for IA32 is installed in /usr/local/lib
+# and the include files in /usr/local/include/efi.
+# 2. gnu-efi lib for x86_64 is installed in /usr/lib
+# and the include files in /usr/include/efi.
+ifeq ($(ARCH),i386)
+ SARCHOPT = -march=i386
+ CARCHOPT = -m32 -march=i386
+ EFI_SUBARCH = ia32
+ LIBDIR = /usr/local/lib
+ EFIINC = /usr/local/include/efi
+endif
+ifeq ($(ARCH),x86_64)
+ SARCHOPT = -march=x86-64
+ CARCHOPT = -m64 -march=x86-64
+ EFI_SUBARCH = $(ARCH)
+ EFIINC = /usr/include/efi
+ LIBDIR=/usr/lib64
+endif
+#LIBDIR=/usr/lib
+FORMAT=efi-app-$(EFI_SUBARCH)
+
+CFLAGS = -I$(EFIINC) -I$(EFIINC)/$(EFI_SUBARCH) \
-DEFI_FUNCTION_WRAPPER -fPIC -fshort-wchar -ffreestanding \
- -Wall -I$(com32)/include -I$(core)/include -m32 -march=i686 \
+ -Wall -I$(com32)/include -I$(com32)/include/sys \
+ -I$(core)/include $(CARCHOPT) \
-I$(com32)/lib/ -std=gnu99 -DELF_DEBUG -DSYSLINUX_EFI
# gnuefi sometimes installs these under a gnuefi/ directory, and sometimes not
-CRT0 := $(shell find $(LIBDIR) -name crt0-efi-$(ARCH).o 2>/dev/null | tail -n1)
-LDSCRIPT := $(shell find $(LIBDIR) -name elf_$(ARCH)_efi.lds 2>/dev/null | tail -n1)
+CRT0 := $(shell find $(LIBDIR) -name crt0-efi-$(EFI_SUBARCH).o 2>/dev/null | tail -n1)
+LDSCRIPT := $(shell find $(LIBDIR) -name elf_$(EFI_SUBARCH)_efi.lds 2>/dev/null | tail -n1)
-LDFLAGS = -T syslinux.ld -Bsymbolic -pie -nostdlib -znocombreloc \
- -L$(LIBDIR) --hash-style=gnu -m elf_i386 $(CRT0) -E
+LDFLAGS = -T $(ARCH)/syslinux.ld -Bsymbolic -pie -nostdlib -znocombreloc \
+ -L$(LIBDIR) --hash-style=gnu -m elf_$(ARCH) $(CRT0) -E
-SFLAGS = $(GCCOPT) $(GCCWARN) -march=i386 \
+SFLAGS = $(GCCOPT) $(GCCWARN) $(SARCHOPT) \
-fomit-frame-pointer -D__COM32__ \
-nostdinc -iwithprefix include \
- -I$(com32)/libutil/include -I$(com32)/include $(GPLINCLUDE)
+ -I$(com32)/libutil/include -I$(com32)/include -I$(com32)/include/sys $(GPLINCLUDE)
.PRECIOUS: %.o
%.o: %.S
diff --git a/mk/elf.mk b/mk/elf.mk
index 83b2c46d..13e2190e 100644
--- a/mk/elf.mk
+++ b/mk/elf.mk
@@ -16,20 +16,32 @@
include $(MAKEDIR)/syslinux.mk
+# Support IA32 and x86_64 platforms with one build
+# Set up architecture specifics; for cross compilation, set ARCH as apt
GCCOPT := $(call gcc_ok,-std=gnu99,)
-GCCOPT += $(call gcc_ok,-m32,)
+ifeq ($(ARCH),i386)
+ GCCOPT += $(call gcc_ok,-m32,)
+ GCCOPT += $(call gcc_ok,-march=i386)
+ GCCOPT += $(call gcc_ok,-mpreferred-stack-boundary=2,)
+endif
+ifeq ($(ARCH),x86_64)
+ GCCOPT += $(call gcc_ok,-m64,)
+ GCCOPT += $(call gcc_ok,-march=x86-64)
+ #let preferred-stack-boundary be default (=4)
+endif
+GCCOPT += -Os -fomit-frame-pointer
GCCOPT += $(call gcc_ok,-fno-stack-protector,)
GCCOPT += $(call gcc_ok,-fwrapv,)
GCCOPT += $(call gcc_ok,-freg-struct-return,)
-GCCOPT += -march=i386 -Os -fomit-frame-pointer
GCCOPT += $(call gcc_ok,-fno-exceptions,)
GCCOPT += $(call gcc_ok,-fno-asynchronous-unwind-tables,)
-GCCOPT += $(call gcc_ok,-fPIE,-fPIC)
+# Note -fPIE does not work with ld on x86_64, try -fPIC instead
+# Does BIOS build depend on -fPIE?
+GCCOPT += $(call gcc_ok,-fPIC)
GCCOPT += $(call gcc_ok,-falign-functions=0,-malign-functions=0)
GCCOPT += $(call gcc_ok,-falign-jumps=0,-malign-jumps=0)
GCCOPT += $(call gcc_ok,-falign-labels=0,-malign-labels=0)
GCCOPT += $(call gcc_ok,-falign-loops=0,-malign-loops=0)
-GCCOPT += $(call gcc_ok,-mpreferred-stack-boundary=2,)
com32 = $(topdir)/com32
@@ -41,12 +53,13 @@ GPLLIB =
GPLINCLUDE =
endif
-CFLAGS = $(GCCOPT) -W -Wall -march=i386 \
+CFLAGS = $(GCCOPT) -W -Wall \
-fomit-frame-pointer -D__COM32__ -DDYNAMIC_MODULE \
-nostdinc -iwithprefix include \
- -I$(com32)/libutil/include -I$(com32)/include $(GPLINCLUDE)
-SFLAGS = $(GCCOPT) -D__COM32__ -march=i386
-LDFLAGS = -m elf_i386 -shared --hash-style=gnu -T $(com32)/lib/elf32.ld
+ -I$(com32)/libutil/include -I$(com32)/include \
+ -I$(com32)/include/sys $(GPLINCLUDE)
+SFLAGS = $(GCCOPT) -D__COM32__
+LDFLAGS = -m elf_$(ARCH) -shared --hash-style=gnu -T $(com32)/lib/$(ARCH)/elf.ld
LIBGCC := $(shell $(CC) $(GCCOPT) --print-libgcc)
LNXCFLAGS = -I$(com32)/libutil/include -W -Wall -O -g -D_GNU_SOURCE
diff --git a/mk/embedded.mk b/mk/embedded.mk
index e8f3ae30..16b2a52b 100644
--- a/mk/embedded.mk
+++ b/mk/embedded.mk
@@ -16,12 +16,30 @@
include $(MAKEDIR)/syslinux.mk
-GCCOPT := $(call gcc_ok,-m32,)
+# Support IA32 and x86_64 platforms with one build
+# Set up architecture specifics; for cross compilation, set ARCH as apt
+# Initialize GCCOPT to null to begin with. Without this, make generates
+# recursive error for GCCOPT
+GCCOPT :=
+ifeq ($(ARCH),i386)
+ GCCOPT := $(call gcc_ok,-m32)
+ GCCOPT += $(call gcc_ok,-march=i386)
+ GCCOPT += $(call gcc_ok,-mpreferred-stack-boundary=2,)
+ GCCOPT += $(call gcc_ok,-mincoming-stack-boundary=2,)
+endif
+ifeq ($(ARCH),x86_64)
+ GCCOPT := $(call gcc_ok,-m64)
+ GCCOPT += $(call gcc_ok,-march=x86-64)
+ #let preferred-stack-boundary and incoming-stack-boundary be default(=4)
+# Somewhere down the line ld barfs requiring -fPIC
+ #GCCOPT += $(call gcc_ok,-fPIC)
+endif
GCCOPT += $(call gcc_ok,-ffreestanding,)
GCCOPT += $(call gcc_ok,-fno-stack-protector,)
GCCOPT += $(call gcc_ok,-fwrapv,)
GCCOPT += $(call gcc_ok,-freg-struct-return,)
-GCCOPT += -march=i386 -Os -fomit-frame-pointer -mregparm=3 -DREGPARM=3 \
+# FIXME: regparam for i386 and x86_64 could be different
+GCCOPT += -Os -fomit-frame-pointer -mregparm=3 -DREGPARM=3 \
-msoft-float
GCCOPT += $(call gcc_ok,-fno-exceptions,)
GCCOPT += $(call gcc_ok,-fno-asynchronous-unwind-tables,)
@@ -30,12 +48,11 @@ GCCOPT += $(call gcc_ok,-falign-functions=0,-malign-functions=0)
GCCOPT += $(call gcc_ok,-falign-jumps=0,-malign-jumps=0)
GCCOPT += $(call gcc_ok,-falign-labels=0,-malign-labels=0)
GCCOPT += $(call gcc_ok,-falign-loops=0,-malign-loops=0)
-GCCOPT += $(call gcc_ok,-mpreferred-stack-boundary=2,)
-GCCOPT += $(call gcc_ok,-mincoming-stack-boundary=2,)
+
LIBGCC := $(shell $(CC) $(GCCOPT) --print-libgcc)
-LD += -m elf_i386
+LD += -m elf_$(ARCH)
# Note: use += for CFLAGS and SFLAGS in case something is set in MCONFIG.local
CFLAGS += $(GCCOPT) -g $(GCCWARN) -Wno-sign-compare $(OPTFLAGS) $(INCLUDES)
diff --git a/mk/lib.mk b/mk/lib.mk
index 7ef51043..13022e20 100644
--- a/mk/lib.mk
+++ b/mk/lib.mk
@@ -2,12 +2,25 @@
include $(MAKEDIR)/syslinux.mk
+# Support IA32 and x86_64 platforms with one build
+# Set up architecture specifics; for cross compilation, set ARCH as apt
GCCOPT := $(call gcc_ok,-std=gnu99,)
-GCCOPT += $(call gcc_ok,-m32,)
+ifeq ($(ARCH),i386)
+ GCCOPT += $(call gcc_ok,-m32,)
+ GCCOPT += $(call gcc_ok,-mpreferred-stack-boundary=2,)
+ MARCH = i386
+endif
+ifeq ($(ARCH),x86_64)
+ GCCOPT += $(call gcc_ok,-m64,)
+ #let preferred-stack-boundary be default(=4)
+ MARCH = x86-64
+endif
GCCOPT += $(call gcc_ok,-fno-stack-protector,)
GCCOPT += $(call gcc_ok,-fwrapv,)
GCCOPT += $(call gcc_ok,-freg-struct-return,)
-GCCOPT += $(call gcc_ok,-fPIE,-fPIC)
+# Note -fPIE does not work with ld on x86_64, try -fPIC instead
+# Does BIOS build require -fPIE?
+GCCOPT += $(call gcc_ok,-fPIC)
GCCOPT += $(call gcc_ok,-fno-exceptions,)
GCCOPT += $(call gcc_ok,-fno-asynchronous-unwind-tables,)
GCCOPT += $(call gcc_ok,-fno-strict-aliasing,)
@@ -15,7 +28,6 @@ GCCOPT += $(call gcc_ok,-falign-functions=0,-malign-functions=0)
GCCOPT += $(call gcc_ok,-falign-jumps=0,-malign-jumps=0)
GCCOPT += $(call gcc_ok,-falign-labels=0,-malign-labels=0)
GCCOPT += $(call gcc_ok,-falign-loops=0,-malign-loops=0)
-GCCOPT += $(call gcc_ok,-mpreferred-stack-boundary=2,)
INCLUDE = -I.
STRIP = strip --strip-all -R .comment -R .note
@@ -33,13 +45,25 @@ LIBFLAGS = -DDYNAMIC_CRC_TABLE -DPNG_NO_CONSOLE_IO \
REQFLAGS = $(GCCOPT) -g -D__COM32__ \
-nostdinc -iwithprefix include -I. -I./sys -I../include \
- -I../../core/include
-OPTFLAGS = -Os -march=i386 -falign-functions=0 -falign-jumps=0 \
+ -I../include/sys -I../../core/include -I$(com32)/lib/ \
+ -I$(com32)/lib/sys/module
+OPTFLAGS = -Os -march=$(MARCH) -falign-functions=0 -falign-jumps=0 \
-falign-labels=0 -ffast-math -fomit-frame-pointer
WARNFLAGS = $(GCCWARN) -Wpointer-arith -Wwrite-strings -Wstrict-prototypes -Winline
+ifdef EFI_BUILD
+#Add console read fixes to rawcon_read.c
+LIBFLAGS += -DSYSLINUX_EFI -DEFI_FUNCTION_WRAPPER
+ifeq ($(ARCH),i386)
+ EFIINC = -I/usr/local/include/efi -I/usr/local/include/efi/ia32
+endif
+ifeq ($(ARCH),x86_64)
+ EFIINC = -I/usr/include/efi -I/usr/include/efi/x86_64
+endif
+REQFLAGS += $(EFIINC)
+endif
CFLAGS = $(OPTFLAGS) $(REQFLAGS) $(WARNFLAGS) $(LIBFLAGS)
-LDFLAGS = -m elf_i386 --hash-style=gnu
+LDFLAGS = -m elf_$(ARCH) --hash-style=gnu
LIBOTHER_OBJS = \
atoi.o atol.o atoll.o calloc.o creat.o \
@@ -152,8 +176,8 @@ LIBLOAD_OBJS = \
syslinux/initramfs_archive.o
LIBMODULE_OBJS = \
- sys/module/common.o sys/module/elf_module.o \
- sys/module/shallow_module.o sys/module/elfutils.o \
+ sys/module/$(ARCH)/common.o sys/module/$(ARCH)/elf_module.o \
+ sys/module/$(ARCH)/shallow_module.o sys/module/elfutils.o \
sys/module/exec.o
# ZIP library object files
diff --git a/mk/syslinux.mk b/mk/syslinux.mk
index 966ca87a..2367af62 100644
--- a/mk/syslinux.mk
+++ b/mk/syslinux.mk
@@ -64,6 +64,12 @@ WGET = wget
com32 = $(topdir)/com32
+# Architecture definition
+SUBARCH := $(shell uname -m | sed -e s/i.86/i386/)
+# on x86_64, ARCH has trailing whitespace
+# strip white spaces in ARCH
+ARCH ?= $(strip $(SUBARCH))
+
# Common warnings we want for all gcc-generated code
GCCWARN := -W -Wall -Wstrict-prototypes
# Extremely useful variant for debugging...