When force_pic is on, build linkstamp objects with PIC.
Previously, linkstamp objects would be built without -fPIC. When linked
into a PIE binary, this leads to text relocations, which causes IFUNC
resolution to segfault (the resolution function is called while the
binary is mapped RW).
RELNOTES: None.
@@ -587,7 +587,8 @@ public final class LinkCommandLine extends CommandLine {
CppModel.PREPROCESSOR_DEFINES_VARIABLE_NAME,
computeAllLinkstampDefines());
// For dynamic libraries, produce position independent code.
- if (linkTargetType == LinkTargetType.DYNAMIC_LIBRARY && ccProvider.toolchainNeedsPic()) {
+ if (cppConfiguration.forcePic()
+ || (linkTargetType == LinkTargetType.DYNAMIC_LIBRARY && ccProvider.toolchainNeedsPic())) {
linkstampVariables.addStringVariable(CppModel.PIC_VARIABLE_NAME, "");
}
return linkstampVariables.build();
