[Bug 2086543] Re: libzstd.a not built with -fPIC flag
Julian Andres Klode
2086543 at bugs.launchpad.net
Thu Nov 7 17:05:53 UTC 2024
I suggest raising this in a Debian bug, but suffice it to say you should
link your shared library against the shared library and not the static
one.
Static libraries are provided for building static binaries only.
This is also not something worth introducing a delta for even if we
think it is wrong, because this should work for the use case it is
intended for.
** Tags added: rls-nn-wontfix
** Changed in: libzstd (Ubuntu)
Status: New => Opinion
--
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to libzstd in Ubuntu.
https://bugs.launchpad.net/bugs/2086543
Title:
libzstd.a not built with -fPIC flag
Status in libzstd package in Ubuntu:
Opinion
Bug description:
1) Summary:
ZSTD static library (libzstd.a) provided in 1.5.5+dfsg2-2build1.1 is
not position-independent. So, linking this library to a shared library
fails.
2) Package Info:
$ apt-cache policy libzstd-dev
libzstd-dev:
Installed: 1.5.5+dfsg2-2build1.1
Candidate: 1.5.5+dfsg2-2build1.1
Version table:
*** 1.5.5+dfsg2-2build1.1 500
500 http://linux-ftp.jf.intel.com/pub/mirrors/ubuntu noble-updates/main amd64 Packages
500 http://linux-ftp.fi.intel.com/pub/mirrors/ubuntu noble-updates/main amd64 Packages
100 /var/lib/dpkg/status
1.5.5+dfsg2-2build1 500
500 http://linux-ftp.jf.intel.com/pub/mirrors/ubuntu noble/main amd64 Packages
500 http://linux-ftp.fi.intel.com/pub/mirrors/ubuntu noble/main amd64 Packages
3) Operating System Info:
$ lsb_release -rd
No LSB modules are available.
Description: Ubuntu 24.04 LTS
Release: 24.04
4) What you expected to happen:
static library should be built with "-fPIC" flag. Conan, for example, distribute zstd with `-fPIC` flag (https://github.com/conan-io/conan-center-index/blob/master/recipes/zstd/all/conanfile.py#L27).
5) What happened instead:
Consider the following reproducer:
-------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <zstd.h>
int main(int argc, const char** argv)
{
char stringToCompress[] = "String to be compressed";
int len = strlen(stringToCompress);
int bound = ZSTD_compressBound(len);
char* dstBuff = (char*)malloc(bound);
int compressedSize = ZSTD_compress(dstBuff, bound,
stringToCompress, len, 1);
printf("Size of original buffer: %d\n", len);
printf("Size of compressed buffer: %d\n", compressedSize);
free(dstBuff);
return 0;
}
--------------------------------
Try compiling this as a shared library by linking static zstd:
$ clang -fPIC -shared <reproducer> /usr/lib/x86_64-linux-gnu/libzstd.a
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libzstd.a(zstd_compress.o): warning: relocation against `ZSTD_copySequencesToSeqStoreNoBlockDelim' in read-only section `.text'
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libzstd.a(zstd_compress.o): relocation R_X86_64_PC32 against symbol `ZSTD_copySequencesToSeqStoreExplicitBlockDelim' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: bad value
clang: error: linker command failed with exit code 1 (use -v to see invocation)
To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/libzstd/+bug/2086543/+subscriptions
More information about the foundations-bugs
mailing list