Compile with -fPIE yet still get warning to recompile with -fPIE
-
I have a program which compiles and links fine on many different linux distros. Today I tried to build on Ubuntu 22 and got the error below on the linking step.
/usr/bin/ld: /commerciallibs/senselockAPI/Linux_X64/Ubuntu/libsenseEIV.a(s4wf.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIE /usr/bin/ld: failed to set dynamic section sizes: bad value collect2: error: ld returned 1 exit status make: *** [Makefile:1005: autocommander] Error 1
I tried cleaning and recompiling with -fPIE flag, but the error remains. I am using C++17 and Qt5/QMake on Ubuntu 22 x86_64. The library file above (libsenseEIV.a) is a commercial library which is precompiled, so I cannot make any changes to it.
I am building an executable (not an SO). Can someone explain what is causing the error and how to fix it?
I have added this to my pri file:
QMAKE_CXXFLAGS -= -fPIC QMAKE_CXXFLAGS += -fPIE
but it makes no difference, error still occurs
-
@jeremy_k The compiler version is:
g++ (Ubuntu 12.2.0-3ubuntu1) 12.2.0
I'm afraid I don't understand your point about wrong direction, but this is interesting. The makefile is completely under the control of QMake...but I copied the line below from stdout at the linking stage with the error present:
g++ -Wl,-rpath,/opt/Qt/5.15.2/gcc_64/lib -Wl,-rpath-link,/opt/Qt/5.15.2/gcc_64/lib -o myapp (...all my .o files)
I then added the -no-pie option to the linker and NO error occured:
g++ -no-pie -Wl,-rpath,/opt/Qt/5.15.2/gcc_64/lib -Wl,-rpath-link,/opt/Qt/5.15.2/gcc_64/lib -o myapp (...all my .o files)
So I have a workaround, but really don't understand whats going on.
- Why is this error occuring only on Ubuntu 22 and not other distros?
- Why do I have to add the no-pie linking option on Ubuntu 22 only?
- Why is QMake not figuring this out and adding the proper switches?
Thanks
@ocgltd said in Compile with -fPIE yet still get warning to recompile with -fPIE:
I then added the -no-pie option to the link and NO error:
g++ -no-pie -Wl,-rpath,/opt/Qt/5.15.2/gcc_64/lib -Wl,-rpath-link,/opt/Qt/5.15.2/gcc_64/lib -o myapp (...all my .o files)
That's what I expected. The input object file that triggers the error, libsenseEIV.a(s4wf.o), is on the left side of the message. That is what the linker is suggesting should be recompiled. As you aren't in a position to make that happen, the linking flags need to change.
So I'm I have a workaround, but really don't understand.
- Why is this error occuring only on Ubuntu 22 and not other distros?
Different default g++ flags perhaps?
- Why do I have to add the no-pie linking option on Ubuntu 22 only?
Same as above.
- Why is QMake not figuring this out and adding the proper switches?
It wouldn't be qmake directly making the decision, but rather the makespec (<Qt build>/mkspecs/<platform>) in use. I'm guessing that there isn't a makespec specific to either Ubuntu 22 or that release of the compiler.
-
I have a program which compiles and links fine on many different linux distros. Today I tried to build on Ubuntu 22 and got the error below on the linking step.
/usr/bin/ld: /commerciallibs/senselockAPI/Linux_X64/Ubuntu/libsenseEIV.a(s4wf.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIE /usr/bin/ld: failed to set dynamic section sizes: bad value collect2: error: ld returned 1 exit status make: *** [Makefile:1005: autocommander] Error 1
I tried cleaning and recompiling with -fPIE flag, but the error remains. I am using C++17 and Qt5/QMake on Ubuntu 22 x86_64. The library file above (libsenseEIV.a) is a commercial library which is precompiled, so I cannot make any changes to it.
I am building an executable (not an SO). Can someone explain what is causing the error and how to fix it?
I have added this to my pri file:
QMAKE_CXXFLAGS -= -fPIC QMAKE_CXXFLAGS += -fPIE
but it makes no difference, error still occurs
@ocgltd said in Compile with -fPIE yet still get warning to recompile with -fPIE:
relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIE
You didn't mention which compiler/version is in use, but this may be a case of reading the error message in the wrong direction.
$ g++ -c a.cpp main.cpp $ g++ -pie -o a.out a.o main.o /bin/ld: a.o: relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIE collect2: error: ld returned 1 exit status $ g++ -o a.out a.o main.o $
-
@ocgltd said in Compile with -fPIE yet still get warning to recompile with -fPIE:
relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIE
You didn't mention which compiler/version is in use, but this may be a case of reading the error message in the wrong direction.
$ g++ -c a.cpp main.cpp $ g++ -pie -o a.out a.o main.o /bin/ld: a.o: relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIE collect2: error: ld returned 1 exit status $ g++ -o a.out a.o main.o $
@jeremy_k The compiler version is:
g++ (Ubuntu 12.2.0-3ubuntu1) 12.2.0
I'm afraid I don't understand your point about wrong direction, but this is interesting. The makefile is completely under the control of QMake...but I copied the line below from stdout at the linking stage with the error present:
g++ -Wl,-rpath,/opt/Qt/5.15.2/gcc_64/lib -Wl,-rpath-link,/opt/Qt/5.15.2/gcc_64/lib -o myapp (...all my .o files)
I then added the -no-pie option to the linker and NO error occured:
g++ -no-pie -Wl,-rpath,/opt/Qt/5.15.2/gcc_64/lib -Wl,-rpath-link,/opt/Qt/5.15.2/gcc_64/lib -o myapp (...all my .o files)
So I have a workaround, but really don't understand whats going on.
- Why is this error occuring only on Ubuntu 22 and not other distros?
- Why do I have to add the no-pie linking option on Ubuntu 22 only?
- Why is QMake not figuring this out and adding the proper switches?
Thanks
-
@jeremy_k The compiler version is:
g++ (Ubuntu 12.2.0-3ubuntu1) 12.2.0
I'm afraid I don't understand your point about wrong direction, but this is interesting. The makefile is completely under the control of QMake...but I copied the line below from stdout at the linking stage with the error present:
g++ -Wl,-rpath,/opt/Qt/5.15.2/gcc_64/lib -Wl,-rpath-link,/opt/Qt/5.15.2/gcc_64/lib -o myapp (...all my .o files)
I then added the -no-pie option to the linker and NO error occured:
g++ -no-pie -Wl,-rpath,/opt/Qt/5.15.2/gcc_64/lib -Wl,-rpath-link,/opt/Qt/5.15.2/gcc_64/lib -o myapp (...all my .o files)
So I have a workaround, but really don't understand whats going on.
- Why is this error occuring only on Ubuntu 22 and not other distros?
- Why do I have to add the no-pie linking option on Ubuntu 22 only?
- Why is QMake not figuring this out and adding the proper switches?
Thanks
@ocgltd said in Compile with -fPIE yet still get warning to recompile with -fPIE:
I then added the -no-pie option to the link and NO error:
g++ -no-pie -Wl,-rpath,/opt/Qt/5.15.2/gcc_64/lib -Wl,-rpath-link,/opt/Qt/5.15.2/gcc_64/lib -o myapp (...all my .o files)
That's what I expected. The input object file that triggers the error, libsenseEIV.a(s4wf.o), is on the left side of the message. That is what the linker is suggesting should be recompiled. As you aren't in a position to make that happen, the linking flags need to change.
So I'm I have a workaround, but really don't understand.
- Why is this error occuring only on Ubuntu 22 and not other distros?
Different default g++ flags perhaps?
- Why do I have to add the no-pie linking option on Ubuntu 22 only?
Same as above.
- Why is QMake not figuring this out and adding the proper switches?
It wouldn't be qmake directly making the decision, but rather the makespec (<Qt build>/mkspecs/<platform>) in use. I'm guessing that there isn't a makespec specific to either Ubuntu 22 or that release of the compiler.