@@ -249,6 +249,12 @@ supported_target() {
249
249
return 1
250
250
fi
251
251
;;
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
+ ;;
252
258
* )
253
259
print_error " Invalid target name '$target '"
254
260
return 1
@@ -390,6 +396,7 @@ cocoa="no"
390
396
softmmu=" yes"
391
397
linux_user=" no"
392
398
bsd_user=" no"
399
+ darwin_user=" no"
393
400
blobs=" yes"
394
401
pkgversion=" "
395
402
pie=" "
@@ -766,6 +773,7 @@ OpenBSD)
766
773
Darwin)
767
774
bsd=" yes"
768
775
darwin=" yes"
776
+ darwin_user=" yes"
769
777
hax=" yes"
770
778
hvf=" yes"
771
779
LDFLAGS_SHARED=" -bundle -undefined dynamic_lookup"
@@ -1119,6 +1127,7 @@ for opt do
1119
1127
--disable-user)
1120
1128
linux_user=" no" ;
1121
1129
bsd_user=" no" ;
1130
+ darwin_user=" no" ;
1122
1131
;;
1123
1132
--enable-user) ;;
1124
1133
--disable-linux-user) linux_user=" no"
@@ -1129,6 +1138,10 @@ for opt do
1129
1138
;;
1130
1139
--enable-bsd-user) bsd_user=" yes"
1131
1140
;;
1141
+ --disable-darwin-user) darwin_user=" no"
1142
+ ;;
1143
+ --enable-darwin-user) darwin_user=" yes"
1144
+ ;;
1132
1145
--enable-pie) pie=" yes"
1133
1146
;;
1134
1147
--disable-pie) pie=" no"
@@ -1439,6 +1452,7 @@ QEMU_CFLAGS="$CPU_CFLAGS $QEMU_CFLAGS"
1439
1452
if [ " $ARCH " = " unknown" ]; then
1440
1453
bsd_user=" no"
1441
1454
linux_user=" no"
1455
+ darwin_user=" no"
1442
1456
fi
1443
1457
1444
1458
default_target_list=" "
@@ -1454,6 +1468,10 @@ fi
1454
1468
if [ " $bsd_user " = " yes" ]; then
1455
1469
mak_wilds=" ${mak_wilds} $source_path /default-configs/*-bsd-user.mak"
1456
1470
fi
1471
+ if [ " $darwin_user " = " yes" ]; then
1472
+ mak_wilds=" ${mak_wilds} $source_path /default-configs/*-darwin-user.mak"
1473
+ fi
1474
+
1457
1475
1458
1476
for config in $mak_wilds ; do
1459
1477
default_target_list=" ${default_target_list} $( basename " $config " .mak) "
@@ -1548,6 +1566,7 @@ disabled with --disable-FEATURE, default is enabled if available:
1548
1566
user supported user emulation targets
1549
1567
linux-user all linux usermode emulation targets
1550
1568
bsd-user all BSD usermode emulation targets
1569
+ darwin-user all MacOS usermode emulation targets
1551
1570
docs build documentation
1552
1571
guest-agent build the QEMU Guest Agent
1553
1572
guest-agent-msi build guest agent Windows MSI installation package
@@ -5591,7 +5610,7 @@ if test "$cpu" = "s390x" ; then
5591
5610
fi
5592
5611
5593
5612
# Probe for the need for relocating the user-only binary.
5594
- if ( [ " $linux_user " = yes ] || [ " $bsd_user " = yes ] ) && [ " $pie " = no ]; then
5613
+ if ( [ " $linux_user " = yes ] || [ " $bsd_user " = yes ] || [ " $darwin_user " = yes ] ) && [ " $pie " = no ]; then
5595
5614
textseg_addr=
5596
5615
case " $cpu " in
5597
5616
arm | i386 | ppc* | s390* | sparc* | x86_64 | x32)
@@ -5604,31 +5623,53 @@ if ( [ "$linux_user" = yes ] || [ "$bsd_user" = yes ] ) && [ "$pie" = no ]; then
5604
5623
textseg_addr=0x60000000
5605
5624
;;
5606
5625
esac
5626
+
5607
5627
if [ -n " $textseg_addr " ]; then
5608
5628
cat > $TMPC << EOF
5609
5629
int main(void) { return 0; }
5610
5630
EOF
5611
- textseg_ldflags=" -Wl,-Ttext-segment=$textseg_addr "
5612
- if ! compile_prog " " " $textseg_ldflags " ; then
5613
- # In case ld does not support -Ttext-segment, edit the default linker
5614
- # script via sed to set the .text start addr. This is needed on FreeBSD
5615
- # at least.
5616
- if ! $ld --verbose > /dev/null 2>&1 ; then
5617
- error_exit \
5618
- " We need to link the QEMU user mode binaries at a" \
5619
- " specific text address. Unfortunately your linker" \
5620
- " doesn't support either the -Ttext-segment option or" \
5621
- " printing the default linker script with --verbose." \
5622
- " If you don't want the user mode binaries, pass the" \
5623
- " --disable-user option to configure."
5624
- fi
5631
+ # 64bit macOS reserves 4GB for page zero to catch truncated pointer to int casts.
5632
+ # Follow suggested Wine configuration from:
5633
+ # https://stackoverflow.com/questions/46916112/osx-ld-why-does-pagezero-size-default-to-4gb-on-64b-osx
5634
+ if [ " $darwin_user " = yes ] ; then
5635
+ pz_size_flag=" ,-pagezero_size,0x1000"
5636
+ else
5637
+ pz_size_flag=" "
5638
+ fi
5625
5639
5640
+ # Check three different sets of ld flags:
5641
+ # default_... for standard gnu ld (Linux)
5642
+ # clang_... for llvm clang
5643
+ # macos_... for macOS built-in ld
5644
+ # If none of the above options are supported, edit the default linker
5645
+ # script via sed to set the .text start addr. This is needed on FreeBSD
5646
+ # at least.
5647
+ default_ldflags=" -Wl,-Ttext-segment=$textseg_addr "
5648
+ clang_ldflags=" -Wl,-image-base,${textseg_addr}${pz_size_flag} "
5649
+ macos_ldflags=" -Wl,-image_base,${textseg_addr}${pz_size_flag} "
5650
+
5651
+ if compile_prog " " " $default_ldflags " ; then
5652
+ textseg_ldflags=" $default_ldflags "
5653
+ elif compile_prog " " " $clang_ldflags " ; then
5654
+ textseg_ldflags=" $clang_ldflags "
5655
+ elif compile_prog " " " $macos_ldflags " ; then
5656
+ textseg_ldflags=" $macos_ldflags "
5657
+ elif $ld --verbose > /dev/null 2>&1 ; then
5626
5658
$ld --verbose | sed \
5627
5659
-e ' 1,/==================================================/d' \
5628
5660
-e ' /==================================================/,$d' \
5629
5661
-e " s/[.] = [0-9a-fx]* [+] SIZEOF_HEADERS/. = $textseg_addr + SIZEOF_HEADERS/" \
5630
5662
-e " s/__executable_start = [0-9a-fx]*/__executable_start = $textseg_addr /" > config-host.ld
5631
5663
textseg_ldflags=" -Wl,-T../config-host.ld"
5664
+ else
5665
+ error_exit \
5666
+ " We need to link the QEMU user mode binaries at a" \
5667
+ " specific text address. Unfortunately your linker" \
5668
+ " doesn't support either the -Ttext-segment option," \
5669
+ " -image_base, -image-base, or printing the default" \
5670
+ " linker script with --verbose." \
5671
+ " If you don't want the user mode binaries, pass the" \
5672
+ " --disable-user option to configure."
5632
5673
fi
5633
5674
fi
5634
5675
fi
@@ -6695,6 +6736,7 @@ target_softmmu="no"
6695
6736
target_user_only=" no"
6696
6737
target_linux_user=" no"
6697
6738
target_bsd_user=" no"
6739
+ target_darwin_user=" no"
6698
6740
case " $target " in
6699
6741
${target_name} -softmmu)
6700
6742
target_softmmu=" yes"
@@ -6707,6 +6749,10 @@ case "$target" in
6707
6749
target_user_only=" yes"
6708
6750
target_bsd_user=" yes"
6709
6751
;;
6752
+ ${target_name} -darwin-user)
6753
+ target_user_only=" yes"
6754
+ target_darwin_user=" yes"
6755
+ ;;
6710
6756
* )
6711
6757
error_exit " Target '$target ' not recognised"
6712
6758
exit 1
6954
7000
if test " $target_linux_user " = " yes" ; then
6955
7001
echo " CONFIG_LINUX_USER=y" >> $config_target_mak
6956
7002
fi
7003
+ if test " $target_darwin_user " = " yes" ; then
7004
+ echo " CONFIG_DARWIN_USER=y" >> $config_target_mak
7005
+ fi
6957
7006
list=" "
6958
7007
if test ! -z " $gdb_xml_files " ; then
6959
7008
for x in $gdb_xml_files ; do
@@ -7068,7 +7117,7 @@ if test "$gprof" = "yes" ; then
7068
7117
fi
7069
7118
fi
7070
7119
7071
- if test " $target_linux_user " = " yes" -o " $target_bsd_user " = " yes" ; then
7120
+ if test " $target_linux_user " = " yes" -o " $target_bsd_user " = " yes" -o " $target_darwin_user " = " yes " ; then
7072
7121
ldflags=" $ldflags $textseg_ldflags "
7073
7122
fi
7074
7123
0 commit comments