@@ -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
@@ -5577,7 +5596,7 @@ if test "$cpu" = "s390x" ; then
5577
5596
fi
5578
5597
5579
5598
# 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
5581
5600
textseg_addr=
5582
5601
case " $cpu " in
5583
5602
arm | i386 | ppc* | s390* | sparc* | x86_64 | x32)
@@ -5590,31 +5609,53 @@ if ( [ "$linux_user" = yes ] || [ "$bsd_user" = yes ] ) && [ "$pie" = no ]; then
5590
5609
textseg_addr=0x60000000
5591
5610
;;
5592
5611
esac
5612
+
5593
5613
if [ -n " $textseg_addr " ]; then
5594
5614
cat > $TMPC << EOF
5595
5615
int main(void) { return 0; }
5596
5616
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
5611
5625
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
5612
5644
$ld --verbose | sed \
5613
5645
-e ' 1,/==================================================/d' \
5614
5646
-e ' /==================================================/,$d' \
5615
5647
-e " s/[.] = [0-9a-fx]* [+] SIZEOF_HEADERS/. = $textseg_addr + SIZEOF_HEADERS/" \
5616
5648
-e " s/__executable_start = [0-9a-fx]*/__executable_start = $textseg_addr /" > config-host.ld
5617
5649
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."
5618
5659
fi
5619
5660
fi
5620
5661
fi
@@ -6677,6 +6718,7 @@ target_softmmu="no"
6677
6718
target_user_only=" no"
6678
6719
target_linux_user=" no"
6679
6720
target_bsd_user=" no"
6721
+ target_darwin_user=" no"
6680
6722
case " $target " in
6681
6723
${target_name} -softmmu)
6682
6724
target_softmmu=" yes"
@@ -6689,6 +6731,10 @@ case "$target" in
6689
6731
target_user_only=" yes"
6690
6732
target_bsd_user=" yes"
6691
6733
;;
6734
+ ${target_name} -darwin-user)
6735
+ target_user_only=" yes"
6736
+ target_darwin_user=" yes"
6737
+ ;;
6692
6738
* )
6693
6739
error_exit " Target '$target ' not recognised"
6694
6740
exit 1
6936
6982
if test " $target_linux_user " = " yes" ; then
6937
6983
echo " CONFIG_LINUX_USER=y" >> $config_target_mak
6938
6984
fi
6985
+ if test " $target_darwin_user " = " yes" ; then
6986
+ echo " CONFIG_DARWIN_USER=y" >> $config_target_mak
6987
+ fi
6939
6988
list=" "
6940
6989
if test ! -z " $gdb_xml_files " ; then
6941
6990
for x in $gdb_xml_files ; do
@@ -7050,7 +7099,7 @@ if test "$gprof" = "yes" ; then
7050
7099
fi
7051
7100
fi
7052
7101
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
7054
7103
ldflags=" $ldflags $textseg_ldflags "
7055
7104
fi
7056
7105
0 commit comments