kernel & addons: Build with the non-legacy GCC even on x86_gcc2h.

Only one code change: for some reason, GCC chokes on the cr3 functions
as macros (throwing errors about invalid registers.) The BSDs have them
as inline functions instead, so they are converted to that here.

Tested and working. There seems to be about a 10% decrease in CPU time
on some compilation benchmarks that I briefly tried.

Change-Id: I31666297394d7619f83fca6ff5f933ddd6f07420
Reviewed-on: https://review.haiku-os.org/c/haiku/+/4515
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
This commit is contained in:
Augustin Cavalier 2021-09-30 18:16:13 -04:00 committed by waddlesplash
parent 407f08de29
commit 7aa5574713
20 changed files with 85 additions and 56 deletions

View File

@ -341,7 +341,7 @@ rule KernelArchitectureSetup architecture
;
# C/C++ flags
local ccBaseFlags = -finline -fno-builtin ;
local ccBaseFlags = -finline -fno-builtin -Wno-main ;
if $(HAIKU_CC_IS_LEGACY_GCC_$(architecture)) != 1 {
if $(HAIKU_CC_IS_CLANG_$(architecture)) != 1 {
@ -468,6 +468,11 @@ rule KernelArchitectureSetup architecture
}
# bootloader-centric flags
HAIKU_BOOT_CCFLAGS
+= -DBOOT_ARCHIVE_IMAGE_OFFSET=$(HAIKU_BOOT_ARCHIVE_IMAGE_OFFSET) ;
HAIKU_BOOT_C++FLAGS
+= -DBOOT_ARCHIVE_IMAGE_OFFSET=$(HAIKU_BOOT_ARCHIVE_IMAGE_OFFSET) ;
local bootTarget ;
for bootTarget in $(HAIKU_BOOT_TARGETS) {
switch $(bootTarget) {
@ -557,11 +562,6 @@ rule KernelArchitectureSetup architecture
# defines
HAIKU_KERNEL_DEFINES += _KERNEL_MODE ;
HAIKU_DEFINES_$(architecture)
+= BOOT_ARCHIVE_IMAGE_OFFSET=$(HAIKU_BOOT_ARCHIVE_IMAGE_OFFSET) ;
# TODO: That doesn't need to be a general define. It's just needed for
# compiling (part of) the boot loader.
# kernel add-on glue code
HAIKU_KERNEL_ADDON_BEGIN_GLUE_CODE = <$(architecture)>crtbeginS.o
<src!system!glue!$(architecture)>haiku_version_glue.o ;

View File

@ -76,9 +76,9 @@ rule SetupBoot
SourceSysHdrs $(sources) : $(TARGET_PRIVATE_KERNEL_HEADERS) ;
}
if $(HAIKU_BOOT_C++_HEADERS_DIR_$(TARGET_PACKAGING_ARCH)) {
if $(HAIKU_BOOT_C++_HEADERS_DIR_$(TARGET_KERNEL_ARCH)) {
SourceSysHdrs $(sources) :
$(HAIKU_BOOT_C++_HEADERS_DIR_$(TARGET_PACKAGING_ARCH)) ;
$(HAIKU_BOOT_C++_HEADERS_DIR_$(TARGET_KERNEL_ARCH)) ;
}
# MultiBootSubDirSetup sets the target boot platform on the target object,
@ -90,6 +90,8 @@ rule SetupBoot
local platform = $(TARGET_BOOT_PLATFORM:U) ;
local object ;
for object in $(objects) {
TARGET_PACKAGING_ARCH on $(object) = $(TARGET_KERNEL_ARCH) ;
# add boot flags for the object
ObjectCcFlags $(object) : $(HAIKU_BOOT_CCFLAGS) $(HAIKU_BOOT_$(platform)_CCFLAGS) $(2) ;
ObjectC++Flags $(object) : $(HAIKU_BOOT_C++FLAGS) $(HAIKU_BOOT_$(platform)_C++FLAGS) $(2) ;
@ -97,13 +99,13 @@ rule SetupBoot
ASFLAGS on $(object) = $(HAIKU_BOOT_CCFLAGS) $(HAIKU_BOOT_$(platform)_CCFLAGS) ;
# override regular CCFLAGS/C++FLAGS, as we don't want them
TARGET_CCFLAGS_$(TARGET_PACKAGING_ARCH) on $(object) = ;
TARGET_C++FLAGS_$(TARGET_PACKAGING_ARCH) on $(object) = ;
TARGET_CCFLAGS_$(TARGET_KERNEL_ARCH) on $(object) = ;
TARGET_C++FLAGS_$(TARGET_KERNEL_ARCH) on $(object) = ;
# override warning flags
TARGET_WARNING_CCFLAGS_$(TARGET_PACKAGING_ARCH) on $(object)
TARGET_WARNING_CCFLAGS_$(TARGET_KERNEL_ARCH) on $(object)
= $(TARGET_KERNEL_WARNING_CCFLAGS) ;
TARGET_WARNING_C++FLAGS_$(TARGET_PACKAGING_ARCH) on $(object)
TARGET_WARNING_C++FLAGS_$(TARGET_KERNEL_ARCH) on $(object)
= $(TARGET_KERNEL_WARNING_C++FLAGS) ;
}
}
@ -118,7 +120,7 @@ rule BootLd
{
# BootLd <name> : <objs> : <linkerscript> : <args> ;
LINK on $(1) = $(TARGET_LD_$(TARGET_PACKAGING_ARCH)) ;
LINK on $(1) = $(TARGET_LD_$(TARGET_KERNEL_ARCH)) ;
LINKFLAGS on $(1) = $(HAIKU_BOOT_$(TARGET_BOOT_PLATFORM:U)_LDFLAGS) $(4) ;
if $(3) { LINKFLAGS on $(1) += --script=$(3) ; }
@ -130,8 +132,8 @@ rule BootLd
libs += [ TargetBootLibsupc++ true ] ;
Depends $(1) : [ TargetBootLibsupc++ ] ;
}
LINKLIBS on $(1) = $(libs) [ TargetBootLibgcc true ] ;
Depends $(1) : [ TargetBootLibgcc ] ;
LINKLIBS on $(1) = $(libs) [ TargetBootLibgcc $(TARGET_KERNEL_ARCH) : true ] ;
Depends $(1) : [ TargetBootLibgcc $(TARGET_KERNEL_ARCH) ] ;
# TODO: Do we really want to invoke SetupBoot here? The objects should
# have been compiled with BootObjects anyway, so we're doing that twice.
@ -205,7 +207,7 @@ actions BootStaticLibraryObjects
# Force recreation of the archive to avoid build errors caused by
# stale dependencies after renaming or deleting object files.
$(RM) "$(1)"
$(HAIKU_AR_$(TARGET_PACKAGING_ARCH)) -r "$(1)" "$(2)" ;
$(HAIKU_AR_$(TARGET_KERNEL_ARCH)) -r "$(1)" "$(2)" ;
}
rule BuildMBR binary : source

View File

@ -5,6 +5,11 @@ rule FQualifiedBuildFeatureName features
# Prepends the name of the current target packaging architecture to the
# given feature names.
if $(features[1]) = "QUALIFIED" {
# We have been pre-supplied a qualified name.
return $(features[2]) ;
}
return $(TARGET_PACKAGING_ARCH):$(features) ;
}

View File

@ -114,7 +114,12 @@ for architecture in $(HAIKU_PACKAGING_ARCHS) {
}
if $(HAIKU_PACKAGING_ARCH) {
KernelArchitectureSetup $(HAIKU_PACKAGING_ARCH) ;
local kernelArch = $(HAIKU_PACKAGING_ARCH) ;
# Always use the non-legacy GCC for the kernel.
if $(kernelArch) = x86_gcc2 {
kernelArch = x86 ;
}
KernelArchitectureSetup $(kernelArch) ;
}
# define primary packaging architecture macro

View File

@ -16,14 +16,16 @@ rule SetupKernel
local object ;
for object in $(objects) {
TARGET_PACKAGING_ARCH on $(object) = $(TARGET_KERNEL_ARCH) ;
# add kernel flags for the object
ObjectCcFlags $(object) : $(TARGET_KERNEL_CCFLAGS) $(2) ;
ObjectC++Flags $(object) : $(TARGET_KERNEL_C++FLAGS) $(2) ;
ObjectDefines $(object) : $(TARGET_KERNEL_DEFINES) ;
# override regular CCFLAGS/C++FLAGS, as we don't want them
TARGET_CCFLAGS_$(TARGET_PACKAGING_ARCH) on $(object) = ;
TARGET_C++FLAGS_$(TARGET_PACKAGING_ARCH) on $(object) = ;
TARGET_CCFLAGS_$(TARGET_KERNEL_ARCH) on $(object) = ;
TARGET_C++FLAGS_$(TARGET_KERNEL_ARCH) on $(object) = ;
# override warning flags
TARGET_WARNING_CCFLAGS_$(TARGET_PACKAGING_ARCH) on $(object)
@ -43,7 +45,7 @@ rule KernelLd
{
# KernelLd <name> : <objs> : <linkerscript> : <args> ;
LINK on $(1) = $(TARGET_LD_$(TARGET_PACKAGING_ARCH)) ;
LINK on $(1) = $(TARGET_LD_$(HAIKU_KERNEL_ARCH)) ;
LINKFLAGS on $(1) = $(4) ;
if $(3) {
@ -103,7 +105,7 @@ actions KernelSo1
export $(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR)
$(2[1]) --data $(2[2]) $(1) &&
$(HAIKU_ELFEDIT_$(TARGET_PACKAGING_ARCH)) --output-type dyn $(1)
$(HAIKU_ELFEDIT_$(HAIKU_KERNEL_ARCH)) --output-type dyn $(1)
}
rule KernelAddon
@ -115,6 +117,8 @@ rule KernelAddon
local libs = $(3) ;
AddResources $(1) : $(4) ;
TARGET_PACKAGING_ARCH on $(target) = $(TARGET_KERNEL_ARCH) ;
local kernel ;
local beginGlue ;
local endGlue ;
@ -164,6 +168,8 @@ rule KernelMergeObject
# will be added.
#
TARGET_PACKAGING_ARCH on $(1) = $(TARGET_KERNEL_ARCH) ;
SetupKernel $(2) : $(3) ;
Objects $(2) ;
MergeObjectFromObjects $(1) : $(2:S=$(SUFOBJ)) : $(4) ;
@ -175,6 +181,8 @@ rule KernelStaticLibrary
# This is designed to take a set of sources and libraries and create
# a static library.
TARGET_PACKAGING_ARCH on $(1) = $(TARGET_KERNEL_ARCH) ;
SetupKernel $(2) : $(3) : false ;
Library $(1) : $(2) ;
}
@ -185,6 +193,8 @@ rule KernelStaticLibraryObjects
# This is designed to take a set of sources and libraries and create
# a file called <name>
TARGET_PACKAGING_ARCH on $(1) = $(TARGET_KERNEL_ARCH) ;
# Show that we depend on the libraries we need
SetupKernel $(2) ;
LocalClean clean : $(1) ;
@ -199,5 +209,5 @@ actions KernelStaticLibraryObjects
# Force recreation of the archive to avoid build errors caused by
# stale dependencies after renaming or deleting object files.
$(RM) "$(1)"
$(HAIKU_AR_$(TARGET_PACKAGING_ARCH)) -r "$(1)" "$(2)" ;
$(HAIKU_AR_$(HAIKU_KERNEL_ARCH)) -r "$(1)" "$(2)" ;
}

View File

@ -258,15 +258,17 @@ actions Ld
$(LINK) $(LINKFLAGS) -o "$(1)" "$(2)" "$(NEEDLIBS)" $(LINKLIBS)
}
rule CreateAsmStructOffsetsHeader header : source
rule CreateAsmStructOffsetsHeader header : source : architecture
{
# CreateAsmStructOffsetsHeader header : source
# CreateAsmStructOffsetsHeader header : source : architecture
#
# Grist will be added to both header and source.
header = [ FGristFiles $(header) ] ;
source = [ FGristFiles $(source) ] ;
TARGET_PACKAGING_ARCH on $(header) = $(architecture) ;
# find out which headers, defines, etc. to use
local headers ;
local sysHeaders ;
@ -367,7 +369,8 @@ rule CreateAsmStructOffsetsHeader header : source
Depends $(header) : $(source) $(PLATFORM) ;
SEARCH on $(source) += $(SEARCH_SOURCE) ;
MakeLocateArch $(header) ;
MakeLocate $(header) : [ FDirName $(TARGET_COMMON_DEBUG_OBJECT_DIR_$(architecture))
system kernel ] ;
LocalClean clean : $(header) ;
HDRRULE on $(source) = HdrRule ;

View File

@ -6,12 +6,13 @@ rule Link
{
# Note: RESFILES must be set before invocation.
local architecture = [ on $(1) return $(TARGET_PACKAGING_ARCH) ] ;
if [ on $(1) return $(PLATFORM) ] = host {
LINK on $(1) = $(HOST_LINK) ;
LINKFLAGS on $(1) = $(HOST_LINKFLAGS) [ on $(1) return $(LINKFLAGS) ] ;
} else {
LINK on $(1) = $(TARGET_LINK_$(TARGET_PACKAGING_ARCH)) ;
LINKFLAGS on $(1) = $(TARGET_LINKFLAGS_$(TARGET_PACKAGING_ARCH))
LINK on $(1) = $(TARGET_LINK_$(architecture)) ;
LINKFLAGS on $(1) = $(TARGET_LINKFLAGS_$(architecture))
[ on $(1) return $(LINKFLAGS) ] ;
}

View File

@ -103,7 +103,7 @@ rule TargetKernelLibsupc++ asPath
flags += path ;
}
return [
BuildFeatureAttribute gcc_syslibs_devel
BuildFeatureAttribute QUALIFIED $(TARGET_KERNEL_ARCH):gcc_syslibs_devel
: libsupc++-kernel.a : $(flags)
] ;
} else {
@ -215,7 +215,7 @@ rule TargetKernelLibgcc asPath
flags += path ;
}
return [
BuildFeatureAttribute gcc_syslibs_devel
BuildFeatureAttribute QUALIFIED $(TARGET_KERNEL_ARCH):gcc_syslibs_devel
: libgcc-kernel.a : $(flags)
] ;
} else {
@ -224,15 +224,15 @@ rule TargetKernelLibgcc asPath
}
rule TargetBootLibgcc asPath
rule TargetBootLibgcc architecture : asPath
{
# TargetBootLibgcc [ <asPath> ]
# TargetBootLibgcc [ architecture ] : [ <asPath> ]
#
# Returns the static bootloader libgcc for the target.
# Invoking with <asPath> = true will return the full library path.
if $(TARGET_PLATFORM) = haiku {
if $(TARGET_PACKAGING_ARCH) = x86_64 {
if $(architecture) = x86_64 {
# we need to use the 32-bit libgcc.a built by the cross-compiler
return $(TARGET_BOOT_LIBGCC) ;
@ -247,7 +247,7 @@ rule TargetBootLibgcc asPath
flags += path ;
}
return [
BuildFeatureAttribute gcc_syslibs_devel
BuildFeatureAttribute QUALIFIED $(architecture):gcc_syslibs_devel
: libgcc-kernel.a : $(flags)
] ;
} else {
@ -292,7 +292,7 @@ rule TargetKernelLibgcceh asPath
flags += path ;
}
return [
BuildFeatureAttribute gcc_syslibs_devel
BuildFeatureAttribute QUALIFIED $(TARGET_KERNEL_ARCH):gcc_syslibs_devel
: libgcc_eh-kernel.a : $(flags)
] ;
} else {

View File

@ -34,8 +34,11 @@
_v; \
})
#define x86_write_cr3(value) \
__asm__("mov %0,%%cr3" : : "r" (value))
static inline void
x86_write_cr3(size_t value)
{
__asm__("mov %0,%%cr3" : : "r" (value) : "memory");
}
#define x86_read_cr4() ({ \
size_t _v; \

View File

@ -12,7 +12,7 @@
SubDirHdrs $(HAIKU_TOP) src add-ons kernel file_systems bfs ;
}
if $(TARGET_PACKAGING_ARCH) = x86_gcc2 {
if $(TARGET_KERNEL_ARCH) = x86_gcc2 {
# GCC2 doesn't compile BFS correctly with -O2 or more
OPTIM = -O1 ;
}

View File

@ -13,7 +13,7 @@ oldOPTIM = $(OPTIM) ;
defines += COMPILE_FOR_R5 ;
}
if $(TARGET_PACKAGING_ARCH) = x86_gcc2 {
if $(TARGET_KERNEL_ARCH) = x86_gcc2 {
# the gcc on BeOS doesn't compile BFS correctly with -O2 or more
OPTIM = -O1 ;
}

View File

@ -63,11 +63,11 @@ rule BuildCoffLoader {
actions BuildCoffLoader bind HACK_COFF {
$(RM) -f $(1)
# get the address of the COFF entry
$(TARGET_OBJCOPY_$(TARGET_PACKAGING_ARCH)) -O symbolsrec $(2) $(2).syms
$(TARGET_OBJCOPY_$(TARGET_KERNEL_ARCH)) -O symbolsrec $(2) $(2).syms
EP=`grep _coff_start $(2).syms | tr -d '\r' | cut -d'$' -f2`
$(RM) -f $(2).syms
# copy to XCOFF format and patch the entry point
$(TARGET_OBJCOPY_$(TARGET_PACKAGING_ARCH)) -O $(COFF_FORMAT) --set-start="0x${EP}" $(2) $(1)
$(TARGET_OBJCOPY_$(TARGET_KERNEL_ARCH)) -O $(COFF_FORMAT) --set-start="0x${EP}" $(2) $(1)
#$(CP) $(2) $(1)
# fill-in some fields objcopy missed
$(HACK_COFF) $(1)
@ -93,7 +93,7 @@ rule BuildBiosLoader {
actions BuildBiosLoader {
$(RM) -f $(1)
$(TARGET_OBJCOPY_$(TARGET_PACKAGING_ARCH)) -O binary $(2) $(1)
$(TARGET_OBJCOPY_$(TARGET_KERNEL_ARCH)) -O binary $(2) $(1)
}
@ -127,12 +127,12 @@ actions BuildEFILoader
$(RM) -f $(1)
if [ "$(OUTPUT_TARGET)" = "binary" ]; then
# no bfd support, fake efi Pe header
$(TARGET_OBJCOPY_$(TARGET_PACKAGING_ARCH)) -j .text -j .sdata -j .data \
$(TARGET_OBJCOPY_$(TARGET_KERNEL_ARCH)) -j .text -j .sdata -j .data \
-j .dynamic -j .dynsym -j .rel* -j .rela* -j .reloc -j .dynstr \
--output-target=$(OUTPUT_TARGET) $(2) $(1)
else
# bfd supports pe + efi for arch
$(TARGET_OBJCOPY_$(TARGET_PACKAGING_ARCH)) -j .text -j .sdata -j .data \
$(TARGET_OBJCOPY_$(TARGET_KERNEL_ARCH)) -j .text -j .sdata -j .data \
-j .dynamic -j .dynsym -j .rel* -j .rela* -j .reloc -j .dynstr \
--output-target=$(OUTPUT_TARGET) \
--subsystem=efi-app $(2) $(1)
@ -222,7 +222,7 @@ rule AtariBootPrgLd
{
# AtariBootPrgLd <name> : <objs> : <linkerscript> : <args> ;
LINK on $(1) = $(TARGET_LD_$(TARGET_PACKAGING_ARCH)) ;
LINK on $(1) = $(TARGET_LD_$(TARGET_KERNEL_ARCH)) ;
LINKFLAGS on $(1) = $(4) ;
if $(3) { LINKFLAGS on $(1) += --script=$(3) ; }
@ -250,7 +250,7 @@ actions AtariBootPrgLd
local extraSources = ;
if $(TARGET_CC_IS_LEGACY_GCC_$(TARGET_PACKAGING_ARCH)) = 1 {
if $(TARGET_CC_IS_LEGACY_GCC_$(TARGET_KERNEL_ARCH)) = 1 {
extraSources += atomic.S ;
}

View File

@ -78,12 +78,12 @@ KernelMergeObject kernel_core.o :
# Generate the header defining macros for C++ structure sizes.
local kernelC++StructSizesHeader = [ FGristFiles kernel_c++_struct_sizes.h ] ;
TARGET_HDRS_$(TARGET_PACKAGING_ARCH) on $(kernelC++StructSizesHeader)
TARGET_HDRS_$(TARGET_KERNEL_ARCH) on $(kernelC++StructSizesHeader)
= [ on $(kernelC++StructSizesHeader)
return $(TARGET_HDRS_$(TARGET_PACKAGING_ARCH)) ]
return $(TARGET_HDRS_$(TARGET_KERNEL_ARCH)) ]
$(TARGET_PRIVATE_KERNEL_HEADERS) ;
CreateAsmStructOffsetsHeader $(kernelC++StructSizesHeader)
: kernel_c++_structs.cpp ;
: kernel_c++_structs.cpp : $(TARGET_KERNEL_ARCH) ;
# We need to specify the dependency on the generated syscalls files explicitly.
Includes [ FGristFiles syscalls.cpp ]

View File

@ -58,5 +58,5 @@ KernelMergeObject kernel_arch_arm.o :
kernel_fdt.a
;
CreateAsmStructOffsetsHeader asm_offsets.h : asm_offsets.cpp ;
CreateAsmStructOffsetsHeader asm_offsets.h : asm_offsets.cpp : $(TARGET_KERNEL_ARCH) ;

View File

@ -82,5 +82,5 @@ KernelMergeObject kernel_arch_m68k.o :
;
CreateAsmStructOffsetsHeader asm_offsets.h : asm_offsets.cpp ;
CreateAsmStructOffsetsHeader asm_offsets.h : asm_offsets.cpp : $(TARGET_KERNEL_ARCH) ;

View File

@ -76,4 +76,4 @@ KernelMergeObject kernel_arch_ppc.o :
kernel_fdt.a
;
CreateAsmStructOffsetsHeader asm_offsets.h : asm_offsets.cpp ;
CreateAsmStructOffsetsHeader asm_offsets.h : asm_offsets.cpp : $(TARGET_KERNEL_ARCH) ;

View File

@ -114,7 +114,7 @@ KernelMergeObject kernel_arch_$(TARGET_KERNEL_ARCH).o :
$(TARGET_KERNEL_PIC_CCFLAGS)
;
CreateAsmStructOffsetsHeader asm_offsets.h : asm_offsets.cpp ;
CreateAsmStructOffsetsHeader asm_offsets.h : asm_offsets.cpp : $(TARGET_KERNEL_ARCH) ;
# We need to specify the dependency on the generated syscalls file explicitly.
Includes [ FGristFiles interrupts.S arch.S signals.cpp signals_asm.S ]

View File

@ -1,7 +1,7 @@
SubDir HAIKU_TOP src system kernel lib arch x86 ;
# find the generated asm_offsets.h
SubDirHdrs [ FDirName $(TARGET_COMMON_DEBUG_OBJECT_DIR_$(TARGET_PACKAGING_ARCH))
SubDirHdrs [ FDirName $(TARGET_COMMON_DEBUG_OBJECT_DIR_$(TARGET_KERNEL_ARCH))
system kernel arch $(TARGET_ARCH) ] ;
SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) generic ] ;

View File

@ -1,8 +1,8 @@
SubDir HAIKU_TOP src system kernel lib arch x86_64 ;
# find the generated asm_offsets.h
SubDirHdrs [ FDirName $(TARGET_COMMON_DEBUG_OBJECT_DIR_$(TARGET_PACKAGING_ARCH))
system kernel arch $(TARGET_KERNEL_ARCH_DIR) ] ;
SubDirHdrs [ FDirName $(TARGET_COMMON_DEBUG_OBJECT_DIR_$(TARGET_KERNEL_ARCH))
system kernel arch $(TARGET_KERNEL_ARCH) ] ;
SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) generic ] ;

View File

@ -150,7 +150,7 @@ for architectureObject in [ MultiArchSubDirSetup ] {
[ FDirName $(SUBDIR) arch $(TARGET_ARCH_$(architecture)) ]
$(TARGET_PRIVATE_SYSTEM_HEADERS_$(architecture)) ;
CreateAsmStructOffsetsHeader $(syscallTypesSizes)
: $(syscallTypesSizesSource) ;
: $(syscallTypesSizesSource) : $(TARGET_PACKAGING_ARCH) ;
#Includes $(syscallInfos) : $(syscallTypesSizes) ;
# explicitly tell jam about the inclusion of the generated header