Menu

#380 Building mpg123 using non-legacy CMake toolchain fails

1.32.x
closed-fixed
nobody
None
5
2025-10-06
2025-09-10
Maarten
No

When using the non-legacy CMake toolchain, linking mpg123 fails with the following error:

ld.lld: error: relocation R_386_GOTOFF cannot be used against symbol 'INT123_costab_mmxsse'; recompile with -fPIC
>>> defined in src/libmpg123/CMakeFiles/libmpg123.dir/home/maarten/programming/mpg123-github-official-fork/src/libmpg123/tabinit_mmx.S.o
>>> referenced by dct64_sse_float.S:83 (/home/maarten/programming/mpg123-github-official-fork/src/libmpg123/dct64_sse_float.S:83)
>>>               src/libmpg123/CMakeFiles/libmpg123.dir/home/maarten/programming/mpg123-github-official-fork/src/libmpg123/dct64_sse_float.S.o:(.text+0x7B)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

Reproducer:

cmake -S ~/projects/mpg123/ports/cmake -B mpg123-android-x86 -GNinja -DCMAKE_TOOLCHAIN_FILE=$HOME/Android/Sdk/ndk/28.2.13676358/build/cmake/android.toolchain.cmake -DANDROID_ABI=x86 -DANDROID_PLATFORM=android-26 -DANDROID_USE_LEGACY_TOOLCHAIN_FILE=OFF -DBUILD_PROGRAMS=OFF -DBUILD_LIBOUT123=OFF -DBUILD_SHARED_LIBS=ON --fresh
cmake --build mpg123-android-x86 --target libmpg123

The following patch fixes the problem (for me):

--- a/src/libmpg123/mangle.h
+++ b/src/libmpg123/mangle.h
@@ -139,7 +139,7 @@ Lpic_base: \
 #endif /* PIC variants */

 // Apple and Android NDK seem both not to like direct global access.
-#if defined(PIC) && (defined(__APPLE__) || defined(ANDROID))
+#if defined(PIC) && (defined(__APPLE__) || defined(__ANDROID__))
 #define PIC_GLOBAL_PTR
 #endif

diff --git a/src/libmpg123/tabinit_mmx.S b/src/libmpg123/tabinit_mmx.S
index 077e19e7..332bcd22 100644

Discussion

  • Maarten

    Maarten - 2025-09-10

    Unrelated to the error, but would this patch make sense?

    diff --git a/src/libmpg123/tabinit_mmx.S b/src/libmpg123/tabinit_mmx.S
    index 077e19e7..332bcd22 100644
    --- a/src/libmpg123/tabinit_mmx.S
    +++ b/src/libmpg123/tabinit_mmx.S
    @@ -10,7 +10,11 @@
    
     #include "mangle.h"
    
    -.data
    +#ifndef __APPLE__
    
    +       .section        .rodata
    +#else
    +       .data
    +#endif
            ALIGN32
     .globl ASM_NAME(INT123_costab_mmxsse)
     ASM_NAME(INT123_costab_mmxsse):
    
     
    • Thomas Orgis

      Thomas Orgis - 2025-09-11

      Am Wed, 10 Sep 2025 14:19:19 -0000
      schrieb "Maarten" pacha2087@users.sourceforge.net:

      -.data
      +#ifndef APPLE
      + .section .rodata
      +#else
      + .data
      +#endif

      Yeah … I guess we probably should define a macro

      #ifndef __APPLE__
      #define RODATA .section .rodata
      #else
      #define RODATA .data
      #endif
      

      and use that everywhere?

       
  • Thomas Orgis

    Thomas Orgis - 2025-09-11

    Am Wed, 10 Sep 2025 14:18:39 -0000
    schrieb "Maarten" pacha2087@users.sourceforge.net:

    // Apple and Android NDK seem both not to like direct global access.
    -#if defined(PIC) && (defined(APPLE) || defined(ANDROID))
    +#if defined(PIC) && (defined(APPLE) || defined(ANDROID))
    #define PIC_GLOBAL_PTR
    #endif

    So our resolution of bug #345 was fauly in putting ANDROID in there? Or
    rather, this used to be defined and now only ANDROID is?

     
    • Maarten

      Maarten - 2025-09-12

      You suggested using __ANDROID__ there.

      __ANDROID__ is a built-in macro, whereas ANDROID is added by the CMake toolchain file.
      Reading the verbose build log, -DANDROID is correctly passed when compiling C sources, but not when assembling S sources.

       

      Last edit: Maarten 2025-09-12
  • Thomas Orgis

    Thomas Orgis - 2025-09-13

    How's the current trunk for both?

     
    • Maarten

      Maarten - 2025-10-05

      Trunk works :)

       
  • Thomas Orgis

    Thomas Orgis - 2025-10-06
    • status: open --> closed-fixed
     

Log in to post a comment.

MongoDB Logo MongoDB