Missing underscore for asm function needed for apple

Issue #623 closed
Arthur111 created an issue

On M2 apple there is an error :

Undefined symbols for architecture arm64:

"x265_entropyStateBits", referenced from:

_x265_costCoeffNxN_neon in pixel-util.S.o

(maybe you meant: _x265_entropyStateBits)

change     movrel          x1, x265_entropyStateBits

to         movrel          x1, _x265_entropyStateBits

in aarch64/pixel-util.S and it compile.

Comments (8)

  1. vargolsoft

    Hi

    Thats fine if the function isn’t bit depth dependant, it looks like there are references to 10 and 12 versions from entropy.cpp.o

    I’m not an asm developer (or a C/C++ one really) but I’ve worked around the issue using a hacked up pre-processor macro

    #define UPFX3(prefix, name) _ ## prefix ## _ ## name
    #define UPFX2(prefix, name) UPFX3(prefix, name)
    #define UPFX(name)          UPFX2(X265_NS, name)
    

    and changed the line to use it

    movrel          x1, UPFX(entropyStateBits)
    

  2. Jim Worrall

    People using Apple Silicone are reporting this error. I’ve gotten it using diverse build processes. The homebrew package manager also fails building it with the same error. When building using cmake, if one has -DENABLE_CLI=OFF in all the cmake commands, the error does not occur, but of course then you get no executable. The error is during the make command and looks like this:

    [ 98%] Building CXX object CMakeFiles/cli.dir/abrEncApp.cpp.o
    [100%] Linking CXX executable x265
    Undefined symbols for architecture arm64:
      "x265_entropyStateBits", referenced from:
          _x265_costCoeffNxN_neon in libx265.a(pixel-util.S.o)
          _x265_10bit_costCoeffNxN_neon in libx265_main10.a(pixel-util.S.o)
          _x265_12bit_costCoeffNxN_neon in libx265_main12.a(pixel-util.S.o)
         (maybe you meant: _x265_entropyStateBits)
    ld: symbol(s) not found for architecture arm64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    make[2]: *** [x265] Error 1
    make[1]: *** [CMakeFiles/cli.dir/all] Error 2
    make: *** [all] Error 2
    JimsMBPro:8bit 
    

  3. Jim Worrall

    Thanks for your work @Arthur111 , I hope the developers check it out.

    I don’t know if it is related, but now I’m getting a somewhat similar error trying to build ffmpeg with the ‘repaired’ build of libx265. It fails during the configure stage with:

    Undefined symbols for architecture arm64:
    "x265_10bit::x265_api_query(int, int, int*)", referenced from:
    _x265_api_query in libx265.a(api.cpp.o)
    "x265_10bit::x265_api_get_206(int)", referenced from:
    _x265_api_get_206 in libx265.a(api.cpp.o)
    "x265_12bit::x265_api_query(int, int, int*)", referenced from:
    _x265_api_query in libx265.a(api.cpp.o)
    "x265_12bit::x265_api_get_206(int)", referenced from:
    _x265_api_get_206 in libx265.a(api.cpp.o)
    ld: symbol(s) not found for architecture arm64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    ERROR: x265 not found using pkg-config
    

    But x265 is found by pkg-config with correct paths:

    JimsMBPro:ffmpeg jim$ pkg-config --libs --cflags x265
    -I/Volumes/Ramdisk/target/include -L/Volumes/Ramdisk/target/lib -lx265
    JimsMBPro:ffmpeg jim$ 
    JimsMBPro:ffmpeg jim$ pkg-config --print-variables x265
    exec_prefix
    includedir
    libdir
    pcfiledir
    prefix
    JimsMBPro:ffmpeg jim$ 
    

  4. vargolsoft

    @Jim Worrall

    Yes thats the error I get linking ffmpeg too, thats why I proposed the more complicated fix it the first response.
    I’ve sent it as a patch to the developers mailing list, but the mail seems stuck in the moderators queue.

    EDIT: more detail, the macros can go it the asm.S or the pixel-util.S file. The code fis in pixel-util.S

    Here’s the patch.

    diff --git a/source/common/aarch64/asm.S b/source/common/aarch64/asm.S
    index 399c37cf2..b81fb254e 100644
    --- a/source/common/aarch64/asm.S
    +++ b/source/common/aarch64/asm.S
    @@ -28,6 +28,11 @@
     #define PFX2(prefix, name) PFX3(prefix, name)
     #define PFX(name)          PFX2(X265_NS, name)
    
    +
    +#define UPFX3(prefix, name) _ ## prefix ## _ ## name
    +#define UPFX2(prefix, name) UPFX3(prefix, name)
    +#define UPFX(name)          UPFX2(X265_NS, name)
    +
     #ifdef __APPLE__
     #define PREFIX 1
     #endif
    diff --git a/source/common/aarch64/pixel-util.S b/source/common/aarch64/pixel-util.S
    index fba9a90d5..49c6b0492 100644
    --- a/source/common/aarch64/pixel-util.S
    +++ b/source/common/aarch64/pixel-util.S
    @@ -2407,7 +2407,7 @@ function PFX(costCoeffNxN_neon)
         // x5 - scanFlagMask
         // x6 - baseCtx
         mov             x0, #0
    -    movrel          x1, x265_entropyStateBits
    +    movrel          x1, UPFX(entropyStateBits)
         mov             x4, #0
         mov             x11, #0
         movi            v31.16b, #0
    

  5. Jim Worrall

    Thanks very much, @vargolsoft. Yes I didn’t understand well at all. I don’t know how to apply a patch, but I’m pretty sure I can find where in the files to change the - and + parts. I hope they’ll incorporate your patch before I have to build it again!

  6. Log in to comment