RPMLINT ask for -fPIE and -pie compiler flag. But it was not recognized.

I tried to build Molequeue package here: https://build.opensuse.org/package/show/home:andythe_great/molequeue

RPMLINT want me to built with -fPIE/-fpie in compiler flags and -pie in linker flags.

RPMLINT report:
   35s] ===============
   37s] molequeue.x86_64: W: position-independent-executable-suggested /usr/bin/molequeue
   37s] This executable should be position independent (all binaries should).  Check
   37s] that it is built with -fPIE/-fpie in compiler flags and -pie in linker flags.

But I add the flag like so.

%prep
%setup -q

%build
export CFLAGS="${CFLAGS} -fPIE" 
export CXXFLAGS="${CXXFLAGS} -fPIE" 
export LDFLAGS="${LDFLAGS} -pie"

%cmake -Wno-dev \
 -DENABLE_RPATH:BOOL=OFF \
 -DCMAKE_SKIP_INSTALL_RPATH:BOOL=YES \
 -DCMAKE_SKIP_RPATH:BOOL=YES \
 -DENABLE_TESTING:BOOL=OFF \
 -DBUILD_DOCUMENTATION:BOOL=ON \
 -DCMAKE_VERBOSE_MAKEFILE:BOOL=TRUE \
 -DPYTHON_EXECUTABLE:FILEPATH=python3 \
 -DCMAKE_BUILD_TYPE:STRING=Release ..

%make_build

pushd docs
doxygen
popd



%install
%make_install -C build

Some how, it was not recognized. Same RPMLINT warning. What did I do wrong?
Thanks.

If you look at %cmake expansion, it does not use $LDFLAGS at all. Set RPM macro %build_ldflags.

I looked up %build_ldflags but could not find any documentation on it. How do I use this?

My spec file currently look like this:

%build
CFLAGS="$CFLAGS -fPIE"
CXXFLAGS="$CXXFLAGS -fPIE"
LDFLAGS="$LDFLAGS -pie"

export CFLAGS="%{optflags}" 
export CXXFLAGS="%{optflags}"
export LDFLAGS="%{optflags}"

%cmake -Wno-dev \
 -DCMAKE_C_FLAGS:STRING="%optflags" \
 -DCMAKE_CXX_FLAGS:STRING="%optflags" \
 -DCMAKE_LD_FLAGS:STRING="%optflags" \
 -DENABLE_RPATH:BOOL=OFF \
 -DCMAKE_SKIP_INSTALL_RPATH:BOOL=YES \
 -DCMAKE_SKIP_RPATH:BOOL=YES \
 -DENABLE_TESTING:BOOL=OFF \
 -DBUILD_DOCUMENTATION:BOOL=ON \
 -DCMAKE_VERBOSE_MAKEFILE:BOOL=TRUE \
 -DPYTHON_EXECUTABLE:FILEPATH=python3 \
 -DCMAKE_BUILD_TYPE:STRING=Release ..

Thanks

Update.

I fix the flag, this is what is left.


%build

%cmake -Wno-dev \
 -DCMAKE_C_FLAGS:STRING="%optflags -fPIE" \
 -DCMAKE_CXX_FLAGS:STRING="%optflags -fPIE" \
 -DCMAKE_LD_FLAGS:STRING="%optflags -pie" \
 -DENABLE_RPATH:BOOL=OFF \
 -DCMAKE_SKIP_INSTALL_RPATH:BOOL=YES \
 -DCMAKE_SKIP_RPATH:BOOL=YES \
 -DENABLE_TESTING:BOOL=OFF \
 -DBUILD_DOCUMENTATION:BOOL=ON \
 -DCMAKE_VERBOSE_MAKEFILE:BOOL=TRUE \
 -DPYTHON_EXECUTABLE:FILEPATH=python3 \
 -DCMAKE_BUILD_TYPE:STRING=Release ..

%make_build

It seems to pass the -fPIE and -pie flag correctly now.
But then the build failed all together.

Any clue what went wrong?
https://build.opensuse.org/package/show/home:andythe_great/molequeue


   74s]  13%] Linking CXX shared library ../../lib/libMoleQueueClient.so
   74s] cd /home/abuild/rpmbuild/BUILD/molequeue-0.9.0/build/molequeue/client && /usr/bin/cmake -E cmake_link_script CMakeFiles/MoleQueueClient.dir/link.txt --verbose=1
   74s] /usr/bin/c++ -fPIC -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -Werror=return-type -flto=auto -g -fPIE -O3 -DNDEBUG -Wl,--fatal-warnings -Wl,--no-undefined -lc -flto=auto -Wl,--as-needed -Wl,--no-undefined -Wl,-z,now -shared -Wl,-soname,libMoleQueueClient.so -o ../../lib/libMoleQueueClient.so CMakeFiles/MoleQueueClient.dir/MoleQueueClient_autogen/mocs_compilation.cpp.o CMakeFiles/MoleQueueClient.dir/client.cpp.o CMakeFiles/MoleQueueClient.dir/jobobject.cpp.o CMakeFiles/MoleQueueClient.dir/jsonrpcclient.cpp.o  /usr/lib64/libQt5Network.so.5.14.1 /usr/lib64/libQt5Core.so.5.14.1 
   74s] /usr/lib64/gcc/x86_64-suse-linux/9/../../../../x86_64-suse-linux/bin/ld: /tmp/libMoleQueueClient.so.MBwiQN.ltrans0.ltrans.o: relocation R_X86_64_PC32 against symbol `_ZN9MoleQueue13JsonRpcClient16staticMetaObjectE' can not be used when making a shared object; recompile with -fPIC
   74s] /usr/lib64/gcc/x86_64-suse-linux/9/../../../../x86_64-suse-linux/bin/ld: final link failed: bad value
   74s] collect2: error: ld returned 1 exit status
   74s] make[2]: *** [molequeue/client/CMakeFiles/MoleQueueClient.dir/build.make:134: lib/libMoleQueueClient.so] Error 1
   74s] make[2]: Leaving directory '/home/abuild/rpmbuild/BUILD/molequeue-0.9.0/build'
   74s] make[1]: *** [CMakeFiles/Makefile2:353: molequeue/client/CMakeFiles/MoleQueueClient.dir/all] Error 2
   74s] make[1]: *** Waiting for unfinished jobs....
   76s] make[2]: Entering directory '/home/abuild/rpmbuild/BUILD/molequeue-0.9.0/build'
   76s]  14%] Linking CXX shared library ../../lib/libMoleQueueServerCore.so
   76s] cd /home/abuild/rpmbuild/BUILD/molequeue-0.9.0/build/molequeue/servercore && /usr/bin/cmake -E cmake_link_script CMakeFiles/MoleQueueServerCore.dir/link.txt --verbose=1
   76s] /usr/bin/c++ -fPIC -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -Werror=return-type -flto=auto -g -fPIE -O3 -DNDEBUG -Wl,--fatal-warnings -Wl,--no-undefined -lc -flto=auto -Wl,--as-needed -Wl,--no-undefined -Wl,-z,now -shared -Wl,-soname,libMoleQueueServerCore.so -o ../../lib/libMoleQueueServerCore.so CMakeFiles/MoleQueueServerCore.dir/MoleQueueServerCore_autogen/mocs_compilation.cpp.o CMakeFiles/MoleQueueServerCore.dir/jsonrpc.cpp.o CMakeFiles/MoleQueueServerCore.dir/localsocketconnection.cpp.o CMakeFiles/MoleQueueServerCore.dir/localsocketconnectionlistener.cpp.o CMakeFiles/MoleQueueServerCore.dir/message.cpp.o CMakeFiles/MoleQueueServerCore.dir/messageidmanager_p.cpp.o  /usr/lib64/libQt5Network.so.5.14.1 /usr/lib64/libQt5Core.so.5.14.1 
   76s] /usr/lib64/gcc/x86_64-suse-linux/9/../../../../x86_64-suse-linux/bin/ld: /tmp/libMoleQueueServerCore.so.63hr9K.ltrans0.ltrans.o: relocation R_X86_64_PC32 against symbol `_ZN10QArrayData11shared_nullE@@Qt_5' can not be used when making a shared object; recompile with -fPIC
   76s] /usr/lib64/gcc/x86_64-suse-linux/9/../../../../x86_64-suse-linux/bin/ld: final link failed: bad value
   76s] collect2: error: ld returned 1 exit status
   76s] make[2]: *** [molequeue/servercore/CMakeFiles/MoleQueueServerCore.dir/build.make:164: lib/libMoleQueueServerCore.so] Error 1
   76s] make[2]: Leaving directory '/home/abuild/rpmbuild/BUILD/molequeue-0.9.0/build'
   76s] make[1]: *** [CMakeFiles/Makefile2:244: molequeue/servercore/CMakeFiles/MoleQueueServerCore.dir/all] Error 2
   76s] make: *** [Makefile:155: all] Error 2
   76s] error: Bad exit status from /var/tmp/rpm-tmp.L7ZXMB (%build)
   76s] 
   76s] 
   76s] RPM build errors:
   76s]     Bad exit status from /var/tmp/rpm-tmp.L7ZXMB (%build)
   76s] ### VM INTERACTION START ###
   79s]    70.879037] sysrq: Power Off
   79s]    70.886709] reboot: Power down
   80s] ### VM INTERACTION END ###

Hi
Can’t win… :wink: AFAIK you should just need the -pie in addition to the required link flags (no %{optflags})


can not be used when making a shared object; recompile with -fPIC

Go back to the one that build and check the buildlog to see where the rpmlint report is failing.

I go back to the one that build, RPMLINT ask for -fPIE and -pie flag, which would failed the build. Forget this, I will just leave it to the repo maintainer to figured it out.

Thanks and happy Valentine day.