Build error on master, on Ubuntu 24.04 vanilla
We regularly build the master branch on vanilla Ubuntu 24.04 on EC2 x64 instances (tonight, ami-04b4f1a9cf54c11d0/amazon/ubuntu/images/hvm-ssd-gp3/ubuntu-noble-24.04-amd64-server-20250115 in us-east-1)
The last time we successfully did (before it failed tonight) was on 2024-12-18 18:42:26 UTC-0500.
So our problem must be related to one or many of the 7 commits of 3 Jan 2025.
You'll find the last few lines of our compile log below. Please let me know if you need more info.
--
We version pinned on 4.1.1 to work around this, so it's not impairing us.
It's really just a heads up. You may close this issue anytime, we just wanted to make you aware of this issue.
--
[stderr] 1048I bits [codesize[i]]++;
[stderr] I ~~~~~~
~NAN
[stderr]/root/mozjpeg/jchuff.c:951:9: note: at offset 33 into destination object 'bits'
bitsiki = # of sumbols with code Lenath k *
of size 33
[stderr] 951 | UINT8 bits [MAX_CLEN + 1]; /* bits[k] = # of symbols with code length k */
[stderr] I ANN
[stdout][ 87%] Linking C shared library libturbojpeg.so
[stderr]/usr/bin/ld: simd/MakeFiles/simd.dir/x86_64/jsimd.c.o: relocation R_X86_64_TPOFF32 against 'simd_support' can not be used when making a shared object;
recompile with -fPIC
[stderr]/usr/bin/ld: failed to set dynamic section sizes: bad value [stderr]collect2: error: ld returned 1 exit status
[stderr]make[2]: *** [MakeFiles/turbojpeg.dir/build.make:1255: libturbojpeg.so.0.3.01
Error 1
[stderr]make[1]: *** [MakeFiles/Makefile2:295: MakeFiles/turbojpeg.dir/all] Error 2
[stderr]make[1]: *** Waiting for unfinished jobs....
[stderr]/root/mozjpeg/jchuff.c: In function 'jpeg_gen_optimal_table' :
[stderr]/root/mozjpeg/jchuff. c: 1048:22: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
[stderr] 1048 | bits[codesize[i]]++;
[stderr]/root/mozjpeg/jchuff.c:951:9: note: at offset 33 into destination object 'bits'
of size 33
[stderr] 951 | UINT8 bits[MAX_CLEN + 1]; /* bits[k] = # of symbols with code length k */
[stderr] | Arr
[stdout][ 87%] Linking C shared library ../libjpeg. so
[stderr]/usr/bin/ld: /simd/CMakeFiles/simd.dir/x86_64/jsimd.c.o: relocation R_X86_64_TPOFF32 against 'simd_support' can not be used when making a shared object; recompile with -fPIC
[stderr]/us/bin/ld: failed to set dynamic section sizes: bad value [stderr]collect2: error: ld returned 1 exit status
[stderr]make[2]: *** [sharedlib/MakeFiles/jpeg.dir/build.make:1119: libjpeg.so.62.4.0 Error 1 [stderr]make[1]: *** [MakeFiles/Makefile2:843: sharedlib/(MakeFiles/jpeg.dir/all]
Error 2
[stderr]make: *** [Makefile:146: all] Error 2
Addendum:
Our compile script is as simple as it gets, on a vanilla EC2 Ubuntu 24.04 x64 instance:
git clone https://github.com/mozilla/mozjpeg.git
cd mozjpeg || exit
cmake -G"Unix Makefiles"
make
make install
I have created a Dockerfile to reproduce the issue with different Ubuntu versions and different commits.
My findings:
- Neither 24.04 nor 22.04 works.
- Last commit that works 15274b901acb75d6d2433e8578f3cfbc6f4f5fd9 from 2024-12-23
- First commit that does not work is c6d33b6d69c06bc8ac8fe7379aed18255552dd70 from 2024-12-23
The latter mentioned has changed a lot in CMakeLists.txt without updating BUILDING.md.
I am able to compile the most recent commit 9b8d11f05e3ae4541ce5251f0e5c20c4cb8733b7 by adding -fPIC to the compiler flags:
export CFLAGS='-fPIC'
cmake -G"Unix Makefiles"
make
Older commits may still fail because of an unlinked math function. Without testing I guess this was fixed in b6e0d504f75733392cd4f22446f442516204a715.
Disclaimer: I am not experienced enough in C to fully understand all implications introduced by adding -fPIC. Therefore, I will not create a pull request on this.
@erictroebs Thanks for the extra info.
Not an experienced C/C++ programmer either, but in a nutshell, the -fPIC flag changes how the compiler computes its references.
While I don't think this compiler flag should be necessary to build the code since it's not included in the build scripts, it might be a useful clue for the developers to pin-point the source of the problem.
Thanks for all the details about how you were able to reproduce.
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
This also happens on alpine linux when compiling from source.
#10 32.17 [ 56%] Building C object CMakeFiles/turbojpeg.dir/wrbmp.c.o
#10 32.34 [ 57%] Building C object CMakeFiles/turbojpeg.dir/wrppm.c.o
#10 32.45 [ 57%] Linking C shared library libturbojpeg.so
#10 32.50 /usr/lib/gcc/x86_64-alpine-linux-musl/13.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: simd/CMakeFiles/simd.dir/x86_64/jsimd.c.o: relocation R_X86_64_TPOFF32 against `simd_support' can not be used when making a shared object; recompile with -fPIC
#10 32.50 /usr/lib/gcc/x86_64-alpine-linux-musl/13.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: failed to set dynamic section sizes: bad value
#10 32.50 collect2: error: ld returned 1 exit status
#10 32.50 make[2]: *** [CMakeFiles/turbojpeg.dir/build.make:1255: libturbojpeg.so.0.3.0] Error 1
#10 32.50 make[1]: *** [CMakeFiles/Makefile2:295: CMakeFiles/turbojpeg.dir/all] Error 2
#10 32.50 make: *** [Makefile:146: all] Error 2
#10 ERROR: process "/bin/sh -c make install" did not complete successfully: exit code: 2
------
> [7/7] RUN make install:
31.79 [ 56%] Building C object CMakeFiles/turbojpeg.dir/rdppm.c.o
32.17 [ 56%] Building C object CMakeFiles/turbojpeg.dir/wrbmp.c.o
32.34 [ 57%] Building C object CMakeFiles/turbojpeg.dir/wrppm.c.o
32.45 [ 57%] Linking C shared library libturbojpeg.so
32.50 /usr/lib/gcc/x86_64-alpine-linux-musl/13.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: simd/CMakeFiles/simd.dir/x86_64/jsimd.c.o: relocation R_X86_64_TPOFF32 against `simd_support' can not be used when making a shared object; recompile with -fPIC
32.50 /usr/lib/gcc/x86_64-alpine-linux-musl/13.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: failed to set dynamic section sizes: bad value
32.50 collect2: error: ld returned 1 exit status
32.50 make[2]: *** [CMakeFiles/turbojpeg.dir/build.make:1255: libturbojpeg.so.0.3.0] Error 1
32.50 make[1]: *** [CMakeFiles/Makefile2:295: CMakeFiles/turbojpeg.dir/all] Error 2
32.50 make: *** [Makefile:146: all] Error 2
------
Execution:
apk add --update --no-cache git mesa mesa-dev libwebp libwebp-tools libpng libpng-dev pngquant optipng gifsicle cmake autoconf automake libtool nasm make pkgconfig bash clang build-base llvm-static llvm-dev clang-static clang-dev libc6-compat libjpeg-turbo-dev
git clone https://github.com/mozilla/mozjpeg.git
cd mozjpeg/build
cmake -G"Unix Makefiles" -DENABLE_STATIC=FALSE -DPNG_SUPPORTED=TRUE ../
make install
The solution from @ValdikSS worked for us :) Thank you very much!