#1150491 reglookup: shared library linked with -fPIE -pie breaks under LTO

#1150491#5
Date:
2026-10-10 07:42:46 UTC
From:
To:
Hi,

In debian/patches/fix-install.patch, -fPIE -pie was prepended to the global LINKFLAGS in SConstruct:
  linkflags = '-fPIE -pie ' + os.environ.get('LDFLAGS','-z relro -z now')

Because LINKFLAGS is inherited by env.SharedLibrary(), libregfi.so is linked with -pie.
When building with link-time optimization (-flto=auto, as in Ubuntu), the code generation happens at link time, producing non-PIC code for the shared library and causing a fatal link error:
  relocation R_X86_64_PC32 against symbol `stderr@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC

Dropping hardcoded '-fPIE -pie' from linkflags in fix-install.patch allows the shared library to link cleanly. Executables remain PIE because GCC defaults to PIE.

Patch below:
--- a/debian/patches/fix-install.patch
+++ b/debian/patches/fix-install.patch
@@ -15,7 +15,7 @@
 +cflags += '-fPIE ' + os.environ.get('CFLAGS','-fstack-protector-strong -D_FORTIFY_SOURCE=2 -O2')

 -linkflags = "-fPIC " + os.environ.get('LDFLAGS',"-Wl,-z,relro,-z,now")
-+linkflags = '-fPIE -pie ' + os.environ.get('LDFLAGS','-z relro -z now')
++linkflags = os.environ.get('LDFLAGS','-z relro -z now')

  lib_src = ['lib/regfi.c',
             'lib/winsec.c',