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

add "-no-pie" to CMAKE_EXE_LINKER_FLAGS for executable Standalone Linux #5653

Closed
tank-trax opened this issue Dec 19, 2021 · 12 comments · Fixed by #5678
Closed

add "-no-pie" to CMAKE_EXE_LINKER_FLAGS for executable Standalone Linux #5653

tank-trax opened this issue Dec 19, 2021 · 12 comments · Fixed by #5678
Labels
Feature Request New feature request Infrastructure Issues related to repository, CI/CD, installers, etc. Linux Issues which only occur on Linux
Milestone

Comments

@tank-trax
Copy link
Collaborator

tank-trax commented Dec 19, 2021

Currently the Standalone for Surge XT and Surge XT FX compile as shared libraries

when adding -fPIE -no-pie to CMAKE_CXX_FLAGS Surge XT and and Surge XT FX Standalones compile as executable

the advantage of the binary being executable rather than a shared library is that it can be opened by double-clicking or click -> Enter from the GUI or file manager

however, these flags appear to need to be removed from or not added to the cmake.flags for the plugins (VST, VST3, AU and LV2), which should remain shared libraries

@tank-trax tank-trax added Feature Request New feature request Linux Issues which only occur on Linux labels Dec 19, 2021
@mkruselj mkruselj added the Infrastructure Issues related to repository, CI/CD, installers, etc. label Dec 19, 2021
@tank-trax
Copy link
Collaborator Author

tank-trax commented Dec 19, 2021

this also works.... building --target surge-staged-assets

cmake -Bbuild -DCMAKE_CXX_FLAGS="-fPIE -no-pie"

in the files

surge-fx_VST3.dir/flags.make
surge-fx_VST3.dir/link.txt

surge-xt_VST3.dir/flags.make
surge-xt_VST3.dir/link.txt

replace -no-pie with -pie

CXX_FLAGS = -fPIC -fPIE -pie

-fPIC -fPIE -no-pie creates an executable
-fPIC -fPIE -pie creates a shared library

then

cmake --build build --config Release --target surge-staged-assets -j4

builds the VST3's as Shared Library and Standalones as Executable

@tank-trax
Copy link
Collaborator Author

this also works and may be a better way to go

cmake -Bbuild -DCMAKE_CXX_FLAGS="-fPIE -pie"

then replace -pie with -no-pie

in

surge-fx_Standalone.dir/flags.make
surge-fx_Standalone.dir/link.txt

surge-fx_Standalone.dir/flags.make
surge-fx_Standalone.dir/link.txt

fpie
pie

@mkruselj mkruselj added this to the Surge XT 1.0 milestone Dec 20, 2021
@baconpaul
Copy link
Collaborator

I think I see the magic to add this to just the standalone in cmake but need Linux which I won’t have for a few days

@tank-trax
Copy link
Collaborator Author

tank-trax commented Dec 21, 2021

-fPIE is already there in the Standalone flags.make files, without adding -DCMAKE_CXX_FLAGS="-fPIE -no-pie"

am testing to see if all it was missing was -no-pie

and it does work

-fPIE is already in the Standalone flags.make files, as opposed to -fPIC, but the default setting when not specified is -pie, which builds the Shared Library

the simple solution is adding -no-pie after -fPIE in the the XT and FX Standalone flags.make files

as well -fPIE -no-pie must also be added to the respective links.txt files otherwise it still builds a Shared Library

@tank-trax tank-trax changed the title add "-fPIE -no-pie" to CMAKE_CXX_FLAGS add "-fPIE -no-pie" to CMAKE_CXX_FLAGS for Standalone Linux Dec 21, 2021
@tank-trax
Copy link
Collaborator Author

this thread may be of interest

as well as this one

@tank-trax
Copy link
Collaborator Author

it's the gcc compiler, it has --enable-default-pie configured

gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.3.0-17ubuntu1~20.04' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-9-HskZEa/gcc-9-9.3.0/debian/tmp-nvptx/usr,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04) 

@tank-trax
Copy link
Collaborator Author

one or all of the following...

-DCMAKE_BUILD_TYPE=Release 
-DCMAKE_SHARED_LINKER_FLAGS="-no-pie" 
-DCMAKE_SHARED_LINKER_FLAGS_RELEASE="-no-pie" 
-DCMAKE_EXE_LINKER_FLAGS="-no-pie"

after trying only

cmake -Bbuild -DCMAKE_EXE_LINKER_FLAGS="-no-pie"

looks to be enough

@tank-trax tank-trax changed the title add "-fPIE -no-pie" to CMAKE_CXX_FLAGS for Standalone Linux add "-no-pie" to CMAKE_EXE_LINKER_FLAGS for executable Standalone Linux Dec 26, 2021
@baconpaul
Copy link
Collaborator

So to be clear: if you use CMAKE_EXE_LINKER_FLAGS="-no-pie" on linux, the problem is solved?

Does this just get solved with editing the README and the azure pipelines script then?

@baconpaul
Copy link
Collaborator

I think the fix might be, in `./CMakeLists.txt' to add

if(UNIX AND NOT APPLE)
   set(CMAKE_EXE_LINKER_FLAGS "-no-pie")
endif()

around line 38 (after the version 17 flag) but I'm really not sure what this will do to every distro out there and all their various configurations and don't know how to test it in all those build envs, which is why I am more leaning towards "README and Azure" btw

@tank-trax
Copy link
Collaborator Author

tank-trax commented Dec 29, 2021

So to be clear: if you use CMAKE_EXE_LINKER_FLAGS="-no-pie" on linux, the problem is solved?

yes, I think it is something that behaves similarly across all Linux distros, if I am reading things correctly it is a GCC issue (-pie is default) as Clang builds the executable without the switch, but I could be wrong about that

the files

surge/build/src/surge-xt/CMakeFiles/surge-xt_Standalone.dir/flags.make
surge/build/src/surge-xt/CMakeFiles/surge-fxt_Standalone.dir/flags.make

for the Standalone have -fPIE rather than -fPIC

CXX_FLAGS = -O3 -DNDEBUG -fPIE...

for the Standalones to be an executable rather than a shared library, it requires -no-pie, so

cmake -Bbuild -DCMAKE_EXE_LINKER_FLAGS="-no-pie"

or

if(UNIX AND NOT APPLE)
   set(CMAKE_EXE_LINKER_FLAGS "-no-pie")
endif()

will add -no-pie into the links.txt file that is in the same folder as the Standalones as follows:

/usr/bin/c++ -O3 -DNDEBUG -no-pie -Wl,--no-undefined...

this builds both XT and FX Standalones as an executable and the VST3's as shared libraries

@baconpaul
Copy link
Collaborator

right OK so then the test is unix and not apple and gcc and not some-get-out-of-jail-ree-cmake-option set it

OK lemme fire up linux and see if i can close this.

@baconpaul
Copy link
Collaborator

paul@paul-linux:~/dev/surge$ file ignore/nopie/surge_xt_products/Surge\ XT
ignore/nopie/surge_xt_products/Surge XT: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=dd10a3f7e95ded839bb10e36671a58fc8439f63f, for GNU/Linux 3.2.0, with debug_info, not stripped
paul@paul-linux:~/dev/surge$ file ignore/nopie/surge_xt_products/Surge\ XT.vst3/Contents/x86_64-linux/Surge\ XT.so 
ignore/nopie/surge_xt_products/Surge XT.vst3/Contents/x86_64-linux/Surge XT.so: ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked, BuildID[sha1]=dcbe8e111d766ce0f25617dfa48b7cb6325de601, with debug_info, not stripped

great so if CI works on 5678 we shoud be good

i added a get-out-of-jail-free override option as well in case it blows up some distro after the 1.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request New feature request Infrastructure Issues related to repository, CI/CD, installers, etc. Linux Issues which only occur on Linux
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants