Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cross Compiling with Meson vs Autotools is causing performance regression #9080

Closed
mrfixit2001 opened this issue Aug 9, 2021 · 19 comments
Closed

Comments

@mrfixit2001
Copy link

I've discovered that when building the dosbox-staging repo that there is a performance loss when compiling the exact same code-base on meson versus autotools.
https://github.com/dosbox-staging/dosbox-staging

You can review my research and progress on this issue here:
dosbox-staging/dosbox-staging#1174

I am using the buildroot toolchain and building for an ARM Cortex A53 board. To confirm the issue, I have removed all custom build flags from the buildroot package so that the environment uses all defaults.

In an attempt to resolve, I have modifying the buildroot pkg-meson.mk file in my build so that it includes the same environment variables as autotools. This has had no effect.

I'm going to paste the resulting compile output directly into this comment rather than using a pastebin, since those tend to expire. First the autotools output, then meson output, both with only default flags used.

AUTOTOOLS:

cd /home/adam/output/build/dosbox-staging-d0bece4181017188dc85a639eb77c7c3a01494a5; 
./autogen.sh;
ac_cv_lbl_unaligned_fail=yes ac_cv_func_mmap_fixed_mapped=yes ac_cv_func_memcmp_working=yes ac_cv_have_decl_malloc=yes gl_cv_func_malloc_0_nonnull=yes ac_cv_func_malloc_0_nonnull=yes ac_cv_func_calloc_0_nonnull=yes ac_cv_func_realloc_0_nonnull=yes lt_cv_sys_lib_search_path_spec="" ac_cv_c_bigendian=no  
PATH="/home/adam/output/host/bin:/home/adam/output/host/sbin:/usr/local/gcc-11.1.0/bin:/home/adam/bin:/home/adam/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin" 
AR="/home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-ar" 
AS="/home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-as" 
LD="/home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-ld" 
NM="/home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-nm" 
CC="/home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-gcc" 
GCC="/home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-gcc" 
CPP="/home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-cpp" 
CXX="/home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-g++" 
FC="/home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-gfortran" 
F77="/home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-gfortran" 
RANLIB="/home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-ranlib" 
READELF="/home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-readelf" 
STRIP="/home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-strip" 
OBJCOPY="/home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-objcopy" 
OBJDUMP="/home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-objdump" 
AR_FOR_BUILD="/usr/bin/ar" 
AS_FOR_BUILD="/usr/bin/as"
CC_FOR_BUILD="/usr/bin/gcc" 
GCC_FOR_BUILD="/usr/bin/gcc" 
CXX_FOR_BUILD="/usr/bin/g++"
LD_FOR_BUILD="/usr/bin/ld" 
CPPFLAGS_FOR_BUILD="-I/home/adam/output/host/include" 
CFLAGS_FOR_BUILD="-O2 -I/home/adam/output/host/include" 
CXXFLAGS_FOR_BUILD="-O2 -I/home/adam/output/host/include" 
LDFLAGS_FOR_BUILD="-L/home/adam/output/host/lib -Wl,-rpath,/home/adam/output/host/lib" 
FCFLAGS_FOR_BUILD="" DEFAULT_ASSEMBLER="/home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-as" 
DEFAULT_LINKER="/home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-ld" 
CPPFLAGS="-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64" 
CFLAGS="-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64  -O3 -g0 -DNDEBUG " 
CXXFLAGS="-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64  -O3 -g0 -DNDEBUG " 
LDFLAGS="" FCFLAGS=" -O3 -g0 -DNDEBUG" FFLAGS=" -O3 -g0 -DNDEBUG" 
PKG_CONFIG="/home/adam/output/host/bin/pkg-config" 
STAGING_DIR="/home/adam/output/host/arm-buildroot-linux-gnueabihf/sysroot" 
INTLTOOL_PERL=/usr/bin/perl 
CROSS_COMPILE="/home/adam/output/host/usr/bin/" 
LIBS="-lvorbisfile -lvorbis -logg" 
./configure 
CPPFLAGS="-DNDEBUG" 
--host="arm-buildroot-linux-gnueabihf" --enable-core-inline --enable-dynrec --enable-unaligned_memory --prefix=/usr --with-sdl-prefix="/home/adam/output/host/arm-buildroot-linux-gnueabihf/sysroot/usr";

Generating build information using aclocal, autoheader, automake and autoconf
This may take a while ...
configure.ac:24: installing './ar-lib'
configure.ac:24: installing './compile'
configure.ac:16: installing './config.guess'
configure.ac:16: installing './config.sub'
configure.ac:20: installing './install-sh'
configure.ac:20: installing './missing'
src/Makefile.am: installing './depcomp'
Now you are ready to run ./configure.
You can also run  ./configure --help for extra features to enable/disable.
configure: WARNING: unrecognized options: --with-sdl-prefix
checking whether make supports nested variables... yes
checking pkg-config is at least version 0.9.0... yes
checking build system type... x86_64-pc-linux-gnu
checking host system type... arm-buildroot-linux-gnueabihf
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for arm-buildroot-linux-gnueabihf-strip... /home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-strip
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports the include directive... yes (GNU style)
checking for arm-buildroot-linux-gnueabihf-gcc... /home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... yes
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether /home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-gcc accepts -g... yes
checking for /home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-gcc option to accept ISO C89... none needed
checking whether /home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-gcc understands -c and -o together... yes
checking dependency style of /home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-gcc... gcc3
checking for arm-buildroot-linux-gnueabihf-ar... /home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-ar
checking the archiver (/home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-ar) interface... ar
checking whether make sets $(MAKE)... (cached) yes
checking for /home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-gcc option to accept ISO C99... none needed
checking how to run the C preprocessor... /home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-cpp
checking whether we are using the GNU C++ compiler... yes
checking whether /home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-g++ accepts -g... yes
checking dependency style of /home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-g++... gcc3
checking for arm-buildroot-linux-gnueabihf-ranlib... /home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-ranlib
checking for a sed that does not truncate output... /bin/sed
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking whether /home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-gcc is Clang... no
checking whether pthreads work with "-pthread" and "-lpthread"... yes
checking for joinable pthread attribute... PTHREAD_CREATE_JOINABLE
checking whether more special flags are required for pthreads... no
checking for PTHREAD_PRIO_INHERIT... yes
checking for SDL... yes
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking SDL_net.h usability... yes
checking SDL_net.h presence... yes
checking for SDL_net.h... yes
checking for SDLNet_Init in -lSDL2_net... yes
checking whether networking features will be enabled... yes 
checking for inline... inline
checking whether byte ordering is bigendian... (cached) no
checking whether struct tm is in sys/time.h or time.h... time.h
checking size of int *... 4
checking whether /home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-g++ supports C++14 features with -std=gnu++14... yes
checking how to run the C++ preprocessor... /home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-g++ -std=gnu++14 -E
checking for stdlib.h... (cached) yes
checking for sys/types.h... (cached) yes
checking for sys/socket.h... yes
checking for netinet/in.h... yes
checking for pwd.h... yes
checking if dirent includes d_type... yes
checking for library containing clock_gettime... none required
checking if compiler allows __builtin_expect... yes
checking for ALSA CFLAGS... 
checking for ALSA LDFLAGS...  -lasound -lm -ldl -lpthread
checking for libasound headers version >= 0.9.0... found.
checking for snd_ctl_open in -lasound... yes
checking whether memory handling in the CPU Core will be inlined... yes
checking for target cpu type... ARMv7 Little Endian
checking whether x86 dynamic cpu core will be enabled... no
checking whether recompiling cpu core will be enabled... yes
checking whether fpu emulation will be enabled... yes
checking whether the x86/x64 assembly fpu core will be enabled... no
checking whether to enable unaligned memory access... yes
checking for libpng... yes
configure: screenshots enabled... using -L/home/adam/output/host/bin/../arm-buildroot-linux-gnueabihf/sysroot/usr/lib -lpng16 -lz 
configure: OPUSFILE dependency can be disabled with --disable-opus-cdda
checking for OPUSFILE... yes
configure: FLUIDSYNTH dependency can be disabled with --disable-fluidsynth
checking for FLUIDSYNTH... yes
configure: WARNING: Roland MT-32 audio synthesizer support disabled. Enable it with --enable-mt32
checking for main in -lGL... no
checking for main in -lopengl32... no
checking GL/gl.h usability... no
checking GL/gl.h presence... no
checking for GL/gl.h... no
checking whether opengl display output will be enabled... no
checking sys/mman.h usability... yes
checking sys/mman.h presence... yes
checking for sys/mman.h... yes
checking for mprotect... yes
checking for realpath... yes
checking for setpriority support... yes
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating docs/Makefile
config.status: creating include/Makefile
config.status: creating src/Makefile
config.status: creating src/cpu/Makefile
config.status: creating src/cpu/core_full/Makefile
config.status: creating src/cpu/core_normal/Makefile
config.status: creating src/cpu/core_dyn_x86/Makefile
config.status: creating src/cpu/core_dynrec/Makefile
config.status: creating src/debug/Makefile
config.status: creating src/dos/Makefile
config.status: creating src/fpu/Makefile
config.status: creating src/gui/Makefile
config.status: creating src/hardware/Makefile
config.status: creating src/hardware/mame/Makefile
config.status: creating src/hardware/serialport/Makefile
config.status: creating src/ints/Makefile
config.status: creating src/libs/Makefile
config.status: creating src/libs/zmbv/Makefile
config.status: creating src/libs/gui_tk/Makefile
config.status: creating src/libs/decoders/Makefile
config.status: creating src/libs/nuked/Makefile
config.status: creating src/libs/ppscale/Makefile
config.status: creating src/midi/Makefile
config.status: creating src/misc/Makefile
config.status: creating src/shell/Makefile
config.status: creating src/platform/Makefile
config.status: creating src/platform/macosx/Makefile
config.status: creating src/platform/visualc/Makefile
config.status: creating tests/Makefile
config.status: creating config.h
config.status: executing depfiles commands
configure: WARNING: unrecognized options: --with-sdl-prefix
>>> dosbox-staging d0bece4181017188dc85a639eb77c7c3a01494a5 Building
PATH="/home/adam/output/host/bin:/home/adam/output/host/sbin:/usr/local/gcc-11.1.0/bin:/home/adam/bin:/home/adam/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"  
/usr/bin/make -j5  -C /home/adam/output/build/dosbox-staging-d0bece4181017188dc85a639eb77c7c3a01494a5/
/usr/bin/make --no-print-directory all-recursive

MESON:

rm -rf /home/adam/output/build/dosbox-staging-d0bece4181017188dc85a639eb77c7c3a01494a5//build
mkdir -p /home/adam/output/build/dosbox-staging-d0bece4181017188dc85a639eb77c7c3a01494a5//build
sed -e 's%@TARGET_CROSS@%/home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-%g' 
-e 's%@TARGET_ARCH@%arm%g' 
-e 's%@TARGET_CPU@%cortex-a53%g' 
-e 's%@TARGET_ENDIAN@%little%g' 
-e "s%@TARGET_CFLAGS@%'-D_LARGEFILE_SOURCE', '-D_LARGEFILE64_SOURCE', '-D_FILE_OFFSET_BITS=64', '-O3', '-g0', '-DNDEBUG'%g" -e "s%@TARGET_LDFLAGS@%%g" 
-e "s%@TARGET_CXXFLAGS@%'-D_LARGEFILE_SOURCE', '-D_LARGEFILE64_SOURCE', '-D_FILE_OFFSET_BITS=64', '-O3', '-g0', '-DNDEBUG'%g" -e 's%@HOST_DIR@%/home/adam/output/host%g' 
-e 's%@STAGING_DIR@%/home/adam/output/host/arm-buildroot-linux-gnueabihf/sysroot%g' 
-e 's%@STATIC@%false%g' -e "/^\[binaries\]$/s:$::" -e "/^\[properties\]$/s:$::" 
package/meson/cross-compilation.conf.in > /home/adam/output/build/dosbox-staging-d0bece4181017188dc85a639eb77c7c3a01494a5//build/cross-compilation.conf
ac_cv_lbl_unaligned_fail=yes ac_cv_func_mmap_fixed_mapped=yes ac_cv_func_memcmp_working=yes ac_cv_have_decl_malloc=yes gl_cv_func_malloc_0_nonnull=yes ac_cv_func_malloc_0_nonnull=yes ac_cv_func_calloc_0_nonnull=yes ac_cv_func_realloc_0_nonnull=yes lt_cv_sys_lib_search_path_spec="" ac_cv_c_bigendian=no  
PATH="/home/adam/output/host/bin:/home/adam/output/host/sbin:/usr/local/gcc-11.1.0/bin:/home/adam/bin:/home/adam/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin" 
AR="/home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-ar" 
AS="/home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-as" 
LD="/home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-ld" 
NM="/home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-nm" 
CC="/home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-gcc" 
GCC="/home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-gcc" 
CPP="/home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-cpp" 
CXX="/home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-g++" 
FC="/home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-gfortran" 
F77="/home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-gfortran" 
RANLIB="/home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-ranlib" 
READELF="/home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-readelf" 
STRIP="/home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-strip" 
OBJCOPY="/home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-objcopy" 
OBJDUMP="/home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-objdump" 
AR_FOR_BUILD="/usr/bin/ar" 
AS_FOR_BUILD="/usr/bin/as" 
CC_FOR_BUILD="/usr/bin/gcc" 
GCC_FOR_BUILD="/usr/bin/gcc" 
CXX_FOR_BUILD="/usr/bin/g++" 
LD_FOR_BUILD="/usr/bin/ld" 
CPPFLAGS_FOR_BUILD="-I/home/adam/output/host/include" 
CFLAGS_FOR_BUILD="-O2 -I/home/adam/output/host/include" 
CXXFLAGS_FOR_BUILD="-O2 -I/home/adam/output/host/include" 
LDFLAGS_FOR_BUILD="-L/home/adam/output/host/lib -Wl,-rpath,/home/adam/output/host/lib" 
FCFLAGS_FOR_BUILD="" DEFAULT_ASSEMBLER="/home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-as" 
DEFAULT_LINKER="/home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-ld" 
CPPFLAGS="-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64" 
CFLAGS="-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64  -O3 -g0 -DNDEBUG " 
CXXFLAGS="-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64  -O3 -g0 -DNDEBUG " 
LDFLAGS="" 
FCFLAGS=" -O3 -g0 -DNDEBUG" 
FFLAGS=" -O3 -g0 -DNDEBUG" 
PKG_CONFIG="/home/adam/output/host/bin/pkg-config" 
STAGING_DIR="/home/adam/output/host/arm-buildroot-linux-gnueabihf/sysroot" 
INTLTOOL_PERL=/usr/bin/perl  
PYTHONNOUSERSITE=y 
/home/adam/output/host/bin/meson 
--prefix=/usr --libdir=lib --default-library=shared --buildtype=release --cross-file=/home/adam/output/build/dosbox-staging-d0bece4181017188dc85a639eb77c7c3a01494a5//build/cross-compilation.conf 
-Db_pie=false -Dstrip=false -Dbuild.pkg_config_path=/home/adam/output/host/lib/pkgconfig -Duse_opengl=false -Duse_sdl2_net=true -Duse_mt32emu=false -Duse_alsa=true -Denable_debugger=none 
/home/adam/output/build/dosbox-staging-d0bece4181017188dc85a639eb77c7c3a01494a5/ 
/home/adam/output/build/dosbox-staging-d0bece4181017188dc85a639eb77c7c3a01494a5//build

The Meson build system
Version: 0.58.2
Source dir: /home/adam/output/build/dosbox-staging-d0bece4181017188dc85a639eb77c7c3a01494a5
Build dir: /home/adam/output/build/dosbox-staging-d0bece4181017188dc85a639eb77c7c3a01494a5/build
Build type: cross build
Project name: dosbox-staging
Project version: 0.77.0
C compiler for the host machine: /home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-gcc (gcc 9.3.0 "arm-buildroot-linux-gnueabihf-gcc.br_real (Buildroot 2021.05-242-gfbff7d7-dirty) 9.3.0")
C linker for the host machine: /home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-gcc ld.bfd 2.32
C++ compiler for the host machine: /home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-g++ (gcc 9.3.0 "arm-buildroot-linux-gnueabihf-g++.br_real (Buildroot 2021.05-242-gfbff7d7-dirty) 9.3.0")
C++ linker for the host machine: /home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-g++ ld.bfd 2.32
C compiler for the build machine: /usr/bin/gcc (gcc 11.1.0 "gcc (GCC) 11.1.0")
C linker for the build machine: /usr/bin/gcc ld.bfd 2.26.1
C++ compiler for the build machine: /usr/bin/g++ (gcc 11.1.0 "g++ (GCC) 11.1.0")
C++ linker for the build machine: /usr/bin/g++ ld.bfd 2.26.1
Build machine cpu family: x86_64
Build machine cpu: x86_64
Host machine cpu family: arm
Host machine cpu: cortex-a53
Target machine cpu family: arm
Target machine cpu: cortex-a53
Compiler for C++ supports arguments -Wextra-semi: YES 
Checking for function "clock_gettime" : YES 
Checking for function "mprotect" : YES 
Checking for function "realpath" : YES 
Checking whether type "struct dirent" has member "d_type" : YES 
Has header "pwd.h" : YES 
Has header "strings.h" : YES 
Has header "netinet/in.h" : YES 
Has header "sys/socket.h" : YES 
Checking if "test for setpriority support" compiles: YES 
Checking if "test for __builtin_expect support" compiles: YES 
Run-time dependency threads found: YES
Found pkg-config: /home/adam/output/host/bin/pkgconf (1.6.3)
Run-time dependency sdl2 found: YES 2.0.12
Run-time dependency sdl2_net found: YES 2.0.1
Run-time dependency fluidsynth found: YES 2.2.1
Run-time dependency opusfile found: YES 0.12
Run-time dependency libpng found: YES 1.6.37
Run-time dependency alsa found: YES 1.2.4
Message: Building dynamic core (dynrec) for ARMV7LE
Message: CPU Supports unaligned memory
Message: Building for little-endian architecture
Configuring config.h using configuration
Run-time dependency GTest found: NO (tried pkgconfig and system)
Looking for a fallback subproject for the dependency gtest
Downloading gtest source from https://github.com/google/googletest/archive/release-1.10.0.zip
<urlopen error unknown url type: https>
A fallback URL could be specified using source_fallback_url key in the wrap file
could not get https://github.com/google/googletest/archive/release-1.10.0.zip is the internet available?
Subproject  gtest is buildable: NO (disabling)
Dependency gtest from subproject subprojects/gtest found: NO (subproject failed to configure)
Message: optional gtest dependency not found, unit tests are disabled
Found git repository at /home/adam/
Program /home/adam/output/host/bin/meson found: YES (/home/adam/output/host/bin/meson)
Build targets in project: 15

dosbox-staging 0.77.0

  Subprojects
    gtest: NO
           could not get https://github.com/google/googletest/archive/release-1.10.0.zip is the internet available?

Found ninja-1.10.2 at /home/adam/output/host/bin/ninja
>>> dosbox-staging d0bece4181017188dc85a639eb77c7c3a01494a5 Building
PATH="/home/adam/output/host/bin:/home/adam/output/host/sbin:/usr/local/gcc-11.1.0/bin:/home/adam/bin:/home/adam/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"  PYTHONNOUSERSITE=y /home/adam/output/host/bin/ninja  -j5  -C /home/adam/output/build/dosbox-staging-d0bece4181017188dc85a639eb77c7c3a01494a5//build
ninja: Entering directory `/home/adam/output/build/dosbox-staging-d0bece4181017188dc85a639eb77c7c3a01494a5//build'

As you can see, I have now modified buildroot itself so that when building with meson it includes all the same default environment variables and config settings as it does with autotools.

In buildroot, Meson uses an SED command to create a cross-compilation.conf file that it uses to generate build commands for all files in the project which is then stored in the build/compile_commands.json file within the dosbox_staging source folder at build-time.
Here is an example from the json file for compiling cpu.cpp:

  {
    "directory": "/home/adam/output/build/dosbox-staging-d0bece4181017188dc85a639eb77c7c3a01494a5/build",
    "command": "/home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-g++ -Isrc/cpu/libcpu.a.p -Isrc/cpu -I../src/cpu -I../include -I. -I.. -I/home/adam/output/host/arm-buildroot-linux-gnueabihf/sysroot/usr/include/SDL2 -fdiagnostics-color=always -Wall -Winvalid-pch -Wnon-virtual-dtor -std=gnu++14 -O3 -Weffc++ -Wextra-semi -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -O3 -g0 -DNDEBUG -fPIC -D_REENTRANT -MD -MQ src/cpu/libcpu.a.p/cpu.cpp.o -MF src/cpu/libcpu.a.p/cpu.cpp.o.d -o src/cpu/libcpu.a.p/cpu.cpp.o -c ../src/cpu/cpu.cpp",
    "file": "../src/cpu/cpu.cpp",
    "output": "src/cpu/libcpu.a.p/cpu.cpp.o"
  },

In an attempt to resolve, one other change I did to dosbox-staging was to patch meson.build to use gnu++14 instead of c++14 (since autotools is using gnu). Sadly, no change in behavior here either.

The devs over at dosbox-staging suggested I reach out here next. I've been actively comparing the two build environments and things are looking to line up closely now.

Just to make things exact, I even tried patching gnu.py to use -MT instead of -MQ, but sadly the issue still did not get resolved.

It's possible that the dosbox-staging meson.build file is missing some flags used by the project, but I went as far as pulling ALL defined flags from the autotools configure results and manually setting them in the meson cflags and cxxflags. Sadly this also had no effect.

I theorize that there is an environment variables that meson isn't uses which autotools does which is causing this regression.

My next thought in trying to resolve is trying to figure out how to tell meson to use the defined default linker that autotools is using (in the environment variables) - as meson appears to be listing the compiler as the linker:
DEFAULT_LINKER="/home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-ld"
C linker for the host machine: /home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-gcc ld.bfd 2.32
C++ linker for the host machine: /home/adam/output/host/bin/arm-buildroot-linux-gnueabihf-g++ ld.bfd 2.32
C linker for the build machine: /usr/bin/gcc ld.bfd 2.26.1
C++ linker for the build machine: /usr/bin/g++ ld.bfd 2.26.1

But at this point I am open to any and all ideas, as my box of tricks is about empty and at this point I'm grasping at straws.

@mensinda
Copy link
Member

mensinda commented Aug 9, 2021

I am not sure if you have already done that, but comparing the actual compiler invocations (ninja -v for Meson and make V=1 for autotools) should at least reveal what flags are different between Meson and autotools.

@mensinda
Copy link
Member

mensinda commented Aug 9, 2021

@xclaesse From what I can tell from skimming through dosbox-staging/dosbox-staging#1174 it is a runtime issue.

@xclaesse
Copy link
Member

xclaesse commented Aug 9, 2021

@mensinda yes I realised that after posting so I deleted the comment, but too late :D

@mrfixit2001
Copy link
Author

mrfixit2001 commented Aug 9, 2021

Awesome that there are already feedback coming in on this! Thank you everyone.

Yes, correct, this is a runtime issue.

Here's a sample output of ninja -v:

/home/adam/r-cade/output/host/bin/arm-buildroot-linux-gnueabihf-g++ -Isrc/cpu/libcpu.a.p -Isrc/cpu -I../src/cpu -I../include -I. -I.. -I/home/adam/r-cade/output/host/arm-buildroot-linux-gnueabihf/sysroot/usr/include/SDL2 -fdiagnostics-color=always -Wall -Winvalid-pch -Wnon-virtual-dtor -std=gnu++14 -O3 -Weffc++ -Wextra-semi -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -O3 -g0 -DNDEBUG -fPIC -D_REENTRANT -MD -MQ src/cpu/libcpu.a.p/cpu.cpp.o -MF src/cpu/libcpu.a.p/cpu.cpp.o.d -o src/cpu/libcpu.a.p/cpu.cpp.o -c ../src/cpu/cpu.cpp

And here's make V=1:

/home/adam/r-cade/output/host/bin/arm-buildroot-linux-gnueabihf-g++ -std=gnu++14 -DHAVE_CONFIG_H -I. -I../..  -I../../include -DNDEBUG -I/home/adam/r-cade/output/host/bin/../arm-buildroot-linux-gnueabihf/sysroot/usr/include/SDL2 -D_REENTRANT    -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64  -O3 -g0 -DNDEBUG   -I/home/adam/r-cade/output/host/bin/../arm-buildroot-linux-gnueabihf/sysroot/usr/include/libpng16  -MT cpu.o -MD -MP -MF .deps/cpu.Tpo -c -o cpu.o cpu.cpp

Just to clarify - I have not specified any build flags manually in either case, both are using what's been defined by default in the buildroot environment and the project files

@xclaesse
Copy link
Member

xclaesse commented Aug 9, 2021

-fPIC could have performance implication.

@xclaesse
Copy link
Member

xclaesse commented Aug 9, 2021

Could be related to #7760 ?

@mrfixit2001
Copy link
Author

-fPIC could have performance implication.

I have been trying to figure out where that's coming from since I posted that... it doesn't seem to be getting added manually anywhere and I can't seem to override the flags to omit it.

@mrfixit2001
Copy link
Author

mrfixit2001 commented Aug 9, 2021

Could be related to #7760 ?

-Db_pie=false is hard-coded into the buildroot meson package so it will always be set for any meson compiles.
I tried changing it to true and yet -fPIC still shows up.

@xclaesse
Copy link
Member

xclaesse commented Aug 9, 2021

I did not follow exactly the PIC story lately, @bonzini surely can help. Try with -Db_staticpic=false -Db_pie=false maybe?

@mrfixit2001
Copy link
Author

Just discovered -Db_staticpic=false removes it, about to see if there's any difference in the compile

@mrfixit2001
Copy link
Author

image info

That does, in fact, seem to be the culprit! Will do some additional compiles to confirm, but it's looking really good!

How would I change this to be the new default for meson? Or does it need to be baked into the meson.build files for the project?

@mensinda
Copy link
Member

mensinda commented Aug 9, 2021

Those options should be added to the default_options around here: https://github.com/dosbox-staging/dosbox-staging/blob/master/meson.build#L4.

@eli-schwartz
Copy link
Member

eli-schwartz commented Aug 9, 2021

Since dosbox-staging presumably really wants this (because it's a performance improvement in this use case), you'd add the -D option to project(default_options: ['b_staticpic=false']).

@xclaesse
Copy link
Member

xclaesse commented Aug 9, 2021

I don't remember why, but most distro enables pic/pie by default nowadays, so meson did too. IIRC it's a tradeoff between performance and security somehow? Not sure.

@eli-schwartz
Copy link
Member

The other option might be, doing this in a granular manner per-target for static_library(..., pic: false)? But that depends on whether you have some static libraries that get installed, and should be pic, and some that are only used for linking into executables.

And yes, it's a security tradeoff -- which generally doesn't cause noticeable performance penalties, but might be for dosbox.

@dcbaker
Copy link
Member

dcbaker commented Aug 9, 2021

Actually, our pic thing is annoying. Setting b_pic=false just means "do the compiler default", which generally means you can't actually turn pic off on Linux. I had patches for that, but they caused a regression, because they changed the meaning of false. I should dust those off again

@mrfixit2001
Copy link
Author

Thank you ALL! I've issued a PR for dosbox-staging to address, and can confirm it resolves the issue against their head-commit. Closing this.

@xclaesse
Copy link
Member

xclaesse commented Aug 9, 2021

@dcbaker Currently we have the choice between "enabled" and "compiler's default", right? I wouldn't be surprised the performance hit is worse on ARM, which is why their cross toolchain does not enable it by default?

@dcbaker
Copy link
Member

dcbaker commented Aug 9, 2021

@xclaesse, yes, exactly. Linux distros turn on PIC by default, IIRC, because ASLR requires PIC for libraries and PIE for executables to work, and the (usually) small performance trade off is worth it for the considerable security benefits for ASLR.

kcgen pushed a commit to dosbox-staging/dosbox-staging that referenced this issue Aug 9, 2021
The meson build system adds -fPIC during compile, which has a negative performance impact. Adding this flags tells meson not to add this flag.

Resolves this issue:
#1174

Further info:
mesonbuild/meson#9080
kcgen pushed a commit to dosbox-staging/dosbox-staging that referenced this issue Aug 11, 2021
The meson build system adds -fPIC during compile, which has a negative performance impact. Adding this flags tells meson not to add this flag.

Resolves this issue:
#1174

Further info:
mesonbuild/meson#9080
kcgen pushed a commit to dosbox-staging/dosbox-staging that referenced this issue Aug 11, 2021
The meson build system adds -fPIC during compile, which has a negative performance impact. Adding this flags tells meson not to add this flag.

Resolves this issue:
#1174

Further info:
mesonbuild/meson#9080
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants