Skip to content

Commit 985d4e9

Browse files
author
tehzz
committed
add darwin-user-* to config script
1 parent 6d7d1fd commit 985d4e9

File tree

8 files changed

+84
-19
lines changed

8 files changed

+84
-19
lines changed

Makefile.target

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,19 @@ obj-y += gdbstub.o
129129

130130
endif #CONFIG_BSD_USER
131131

132+
#########################################################
133+
# macOS user emulator target
134+
135+
ifdef CONFIG_DARWIN_USER
136+
137+
QEMU_CFLAGS+=-I$(SRC_PATH)/darwin-user -I$(SRC_PATH)/darwin-user/$(TARGET_ABI_DIR) \
138+
-I$(SRC_PATH)/darwin-user/$(HOST_VARIANT_DIR)
139+
140+
obj-y += darwin-user/
141+
obj-y += gdbstub.o
142+
143+
endif #CONFIG_DARWIN_USER
144+
132145
#########################################################
133146
# System emulator target
134147
ifdef CONFIG_SOFTMMU

configure

Lines changed: 65 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,12 @@ supported_target() {
249249
return 1
250250
fi
251251
;;
252+
*-darwin-user)
253+
if test "$darwin" != "yes"; then
254+
print_error "Target '$target' is only available on a Darwin host"
255+
return 1
256+
fi
257+
;;
252258
*)
253259
print_error "Invalid target name '$target'"
254260
return 1
@@ -390,6 +396,7 @@ cocoa="no"
390396
softmmu="yes"
391397
linux_user="no"
392398
bsd_user="no"
399+
darwin_user="no"
393400
blobs="yes"
394401
pkgversion=""
395402
pie=""
@@ -766,6 +773,7 @@ OpenBSD)
766773
Darwin)
767774
bsd="yes"
768775
darwin="yes"
776+
darwin_user="yes"
769777
hax="yes"
770778
hvf="yes"
771779
LDFLAGS_SHARED="-bundle -undefined dynamic_lookup"
@@ -1119,6 +1127,7 @@ for opt do
11191127
--disable-user)
11201128
linux_user="no" ;
11211129
bsd_user="no" ;
1130+
darwin_user="no" ;
11221131
;;
11231132
--enable-user) ;;
11241133
--disable-linux-user) linux_user="no"
@@ -1129,6 +1138,10 @@ for opt do
11291138
;;
11301139
--enable-bsd-user) bsd_user="yes"
11311140
;;
1141+
--disable-darwin-user) darwin_user="no"
1142+
;;
1143+
--enable-darwin-user) darwin_user="yes"
1144+
;;
11321145
--enable-pie) pie="yes"
11331146
;;
11341147
--disable-pie) pie="no"
@@ -1439,6 +1452,7 @@ QEMU_CFLAGS="$CPU_CFLAGS $QEMU_CFLAGS"
14391452
if [ "$ARCH" = "unknown" ]; then
14401453
bsd_user="no"
14411454
linux_user="no"
1455+
darwin_user="no"
14421456
fi
14431457

14441458
default_target_list=""
@@ -1454,6 +1468,10 @@ fi
14541468
if [ "$bsd_user" = "yes" ]; then
14551469
mak_wilds="${mak_wilds} $source_path/default-configs/*-bsd-user.mak"
14561470
fi
1471+
if [ "$darwin_user" = "yes" ]; then
1472+
mak_wilds="${mak_wilds} $source_path/default-configs/*-darwin-user.mak"
1473+
fi
1474+
14571475

14581476
for config in $mak_wilds; do
14591477
default_target_list="${default_target_list} $(basename "$config" .mak)"
@@ -1548,6 +1566,7 @@ disabled with --disable-FEATURE, default is enabled if available:
15481566
user supported user emulation targets
15491567
linux-user all linux usermode emulation targets
15501568
bsd-user all BSD usermode emulation targets
1569+
darwin-user all MacOS usermode emulation targets
15511570
docs build documentation
15521571
guest-agent build the QEMU Guest Agent
15531572
guest-agent-msi build guest agent Windows MSI installation package
@@ -5577,7 +5596,7 @@ if test "$cpu" = "s390x" ; then
55775596
fi
55785597

55795598
# Probe for the need for relocating the user-only binary.
5580-
if ( [ "$linux_user" = yes ] || [ "$bsd_user" = yes ] ) && [ "$pie" = no ]; then
5599+
if ( [ "$linux_user" = yes ] || [ "$bsd_user" = yes ] || [ "$darwin_user" = yes ] ) && [ "$pie" = no ]; then
55815600
textseg_addr=
55825601
case "$cpu" in
55835602
arm | i386 | ppc* | s390* | sparc* | x86_64 | x32)
@@ -5590,31 +5609,53 @@ if ( [ "$linux_user" = yes ] || [ "$bsd_user" = yes ] ) && [ "$pie" = no ]; then
55905609
textseg_addr=0x60000000
55915610
;;
55925611
esac
5612+
55935613
if [ -n "$textseg_addr" ]; then
55945614
cat > $TMPC <<EOF
55955615
int main(void) { return 0; }
55965616
EOF
5597-
textseg_ldflags="-Wl,-Ttext-segment=$textseg_addr"
5598-
if ! compile_prog "" "$textseg_ldflags"; then
5599-
# In case ld does not support -Ttext-segment, edit the default linker
5600-
# script via sed to set the .text start addr. This is needed on FreeBSD
5601-
# at least.
5602-
if ! $ld --verbose >/dev/null 2>&1; then
5603-
error_exit \
5604-
"We need to link the QEMU user mode binaries at a" \
5605-
"specific text address. Unfortunately your linker" \
5606-
"doesn't support either the -Ttext-segment option or" \
5607-
"printing the default linker script with --verbose." \
5608-
"If you don't want the user mode binaries, pass the" \
5609-
"--disable-user option to configure."
5610-
fi
5617+
# 64bit macOS reserves 4GB for page zero to catch truncated pointer to int casts.
5618+
# Follow suggested Wine configuration from:
5619+
# https://stackoverflow.com/questions/46916112/osx-ld-why-does-pagezero-size-default-to-4gb-on-64b-osx
5620+
if [ "$darwin_user" = yes ] ; then
5621+
pz_size_flag=",-pagezero_size,0x1000"
5622+
else
5623+
pz_size_flag=""
5624+
fi
56115625

5626+
# Check three different sets of ld flags:
5627+
# default_... for standard gnu ld (Linux)
5628+
# clang_... for llvm clang
5629+
# macos_... for macOS built-in ld
5630+
# If none of the above options are supported, edit the default linker
5631+
# script via sed to set the .text start addr. This is needed on FreeBSD
5632+
# at least.
5633+
default_ldflags="-Wl,-Ttext-segment=$textseg_addr"
5634+
clang_ldflags="-Wl,-image-base,${textseg_addr}${pz_size_flag}"
5635+
macos_ldflags="-Wl,-image_base,${textseg_addr}${pz_size_flag}"
5636+
5637+
if compile_prog "" "$default_ldflags"; then
5638+
textseg_ldflags="$default_ldflags"
5639+
elif compile_prog "" "$clang_ldflags"; then
5640+
textseg_ldflags="$clang_ldflags"
5641+
elif compile_prog "" "$macos_ldflags"; then
5642+
textseg_ldflags="$macos_ldflags"
5643+
elif $ld --verbose >/dev/null 2>&1; then
56125644
$ld --verbose | sed \
56135645
-e '1,/==================================================/d' \
56145646
-e '/==================================================/,$d' \
56155647
-e "s/[.] = [0-9a-fx]* [+] SIZEOF_HEADERS/. = $textseg_addr + SIZEOF_HEADERS/" \
56165648
-e "s/__executable_start = [0-9a-fx]*/__executable_start = $textseg_addr/" > config-host.ld
56175649
textseg_ldflags="-Wl,-T../config-host.ld"
5650+
else
5651+
error_exit \
5652+
"We need to link the QEMU user mode binaries at a" \
5653+
"specific text address. Unfortunately your linker" \
5654+
"doesn't support either the -Ttext-segment option," \
5655+
"-image_base, -image-base, or printing the default" \
5656+
"linker script with --verbose." \
5657+
"If you don't want the user mode binaries, pass the" \
5658+
"--disable-user option to configure."
56185659
fi
56195660
fi
56205661
fi
@@ -6677,6 +6718,7 @@ target_softmmu="no"
66776718
target_user_only="no"
66786719
target_linux_user="no"
66796720
target_bsd_user="no"
6721+
target_darwin_user="no"
66806722
case "$target" in
66816723
${target_name}-softmmu)
66826724
target_softmmu="yes"
@@ -6689,6 +6731,10 @@ case "$target" in
66896731
target_user_only="yes"
66906732
target_bsd_user="yes"
66916733
;;
6734+
${target_name}-darwin-user)
6735+
target_user_only="yes"
6736+
target_darwin_user="yes"
6737+
;;
66926738
*)
66936739
error_exit "Target '$target' not recognised"
66946740
exit 1
@@ -6936,6 +6982,9 @@ fi
69366982
if test "$target_linux_user" = "yes" ; then
69376983
echo "CONFIG_LINUX_USER=y" >> $config_target_mak
69386984
fi
6985+
if test "$target_darwin_user" = "yes" ; then
6986+
echo "CONFIG_DARWIN_USER=y" >> $config_target_mak
6987+
fi
69396988
list=""
69406989
if test ! -z "$gdb_xml_files" ; then
69416990
for x in $gdb_xml_files; do
@@ -7050,7 +7099,7 @@ if test "$gprof" = "yes" ; then
70507099
fi
70517100
fi
70527101

7053-
if test "$target_linux_user" = "yes" -o "$target_bsd_user" = "yes" ; then
7102+
if test "$target_linux_user" = "yes" -o "$target_bsd_user" = "yes" -o "$target_darwin_user" = "yes" ; then
70547103
ldflags="$ldflags $textseg_ldflags"
70557104
fi
70567105

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Default configuration for irix-darwin-user
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
# Default configuration for mips-linux-user
1+
# Default configuration for irix-linux-user
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Default configuration for irix64-darwin-user
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
# Default configuration for mips64-linux-user
1+
# Default configuration for irix64-linux-user
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Default configuration for irixn32-darwin-user
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
# Default configuration for mipsn32-linux-user
1+
# Default configuration for irixn32-linux-user

0 commit comments

Comments
 (0)