Missing -DPIC for ARM causes link error on alpine when using -static-pie
Hello, I ran into an issue linking ffmpeg with x265 master (931178347b3f73e40798fd5180209654536bbaa5) on alpine using -static-pie (fails with read-only segment has dynamic relocations
).
I managed to track it down to a missing -DPIC
when building the ARM asm code. In my case it was fixed it by adding -DPIC
to https://bitbucket.org/multicoreware/x265_git/src/931178347b3f73e40798fd5180209654536bbaa5/source/CMakeLists.txt#lines-263. I guess there is some nicer way of doing it but I couldn’t not understand how ENABLE_PIC
is used and when -fPIC
is added.
I haven’t tried but maybe the missing -DPIC
also causes issues for other ARM build configurations?
Comments (6)
-
-
reporter Thanks for the additional details!
-
reporter Looks like a fix was commited https://bitbucket.org/multicoreware/x265_git/commits/02a961bcd26cb299108a2065692500ab895059e9
-
I think commit 38cf1c379b5af08856bb2fdd65f65a1f99384886 (remove an incorrect
#elif defined(PIC)
) fixed the issue. Most modern architectures including aarch64 don’t needPIC
vs non-`PIC` differences. -
reporter Aha i see. In my case i think i did link when i used -static but not -static-pie for som reason
-
But armv7 (the 32-bit) is still broken even in 3.6 :-( See issue #959…
- Log in to comment
x265
source/common/aarch64/asm.S
has a ldr instruction which will lead to an absolute relocationR_AARCH64_ABS64
. It will trigger an errorwhen text relocations are disabled (default in ld.lld. See https://maskray.me/blog/2020-12-19-lld-and-gnu-linker-incompatibilities#:~:text=Text relocations)..) For GNU ld, there will be an error as well if binutils is configured with
--enable-textrel-check=error
.https://mailman.videolan.org/pipermail/x265-devel/2022-August/013487.html is a patch to fix the issue. I have pinged the thread multiple times but no luck so far :(
An aarch64 build does not exercise a code path related to
%define PIC
(only insource/common/x86/x86inc.asm
) or-DPIC
. Actually, modern architectures which don't have PIC costs generally do not have NOPIC/PIC code paths.