Missing -DPIC for ARM causes link error on alpine when using -static-pie

Issue #619 new
Mattias Wadman created an issue

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 -fPICis added.

I haven’t tried but maybe the missing -DPIC also causes issues for other ARM build configurations?

Comments (6)

  1. Ray Song

    x265 source/common/aarch64/asm.S has a ldr instruction which will lead to an absolute relocation R_AARCH64_ABS64. It will trigger an error
    when 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 in source/common/x86/x86inc.asm) or -DPIC. Actually, modern architectures which don't have PIC costs generally do not have NOPIC/PIC code paths.

  2. Mattias Wadman reporter

    Aha i see. In my case i think i did link when i used -static but not -static-pie for som reason

  3. Log in to comment