[Bug 2086543] Re: libzstd.a not built with -fPIC flag

Sudhakar Verma 2086543 at bugs.launchpad.net
Wed Nov 6 09:28:43 UTC 2024


Did you try building with

```
$ clang -fPIC -shared <reproducer> -o lol -lzstd
```

I am able to build with

```
$ clang-15 -fPIC -shared 2086543.c -o lol -lzstd

$ # this will fail
$ clang-15 -fPIC -shared 2086543.c -o lol /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)
```

-- 
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:
  New

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