math icon indicating copy to clipboard operation
math copied to clipboard

Unable to build `flint_sys` with `cargo build`(?)

Open gerblesh opened this issue 9 months ago • 7 comments

Describe the bug Hi! Thanks for making this crate! I'm running into some build issues when running the standard cargo build presumably being something to do with flint_sys. I have added it as a dependency as I needed some of the niche factoring features, but I have tried building with and without flint_sys as a direct dependency and it seems to still have trouble.

To Reproduce

use qfall_math::integer::Z;

fn main() {
    let my_int = Z::from(20);
    println!("{:?}", my_int + Z::from(50));
}

Expected behavior The crate builds and the program can run

Screenshots

Desktop (please complete the following information):

  • OS: Fedora Silverblue
  • Version of qFALL-math: 0.1.0

Additional context build logs:

error: linking with `cc` failed: exit status: 1
                                        |
  = note:  "cc" "-m64" "/tmp/rustcVmuUbt/symbols.o" "<6 object files omitted>" "-Wl,--as-needed" "-Wl,-Bstatic" "/home/user/Documents/Rust/qfall-test/target/debug/deps/{libqfall_math-158a29ecd42e90b7.rlib,librand_distr-ef1d79c8d18a231e.rlib,libnum_traits-d310152ca9e14d1b.rlib,libregex-d9d93d515fccce4a.rlib,libregex_automata-4b9c47d57f4f27cd.rlib,libaho_corasick-34ce0f37332b0ceb.rlib,libmemchr-3dd7c4eee1e54167.rlib,libregex_syntax-f0b266d216f98324.rlib,libstring_builder-64b54de7182e57f4.rlib,librand-a4b9e5a925b97bd9.rlib,librand_chacha-a3fdeb35b99edb2b.rlib,libppv_lite86-2272e97e649624c5.rlib,libzerocopy-89781b5267f25207.rlib,librand_core-f2b8b8f0bf094130.rlib,libgetrandom-05950de74433556d.rlib,libcfg_if-2262c59ed30cbfdf.rlib,libprobability-16ea7b2314483598.rlib,libspecial-42e511413c5f1f79.rlib,liblibm-062b0ffaab479e1d.rlib,librandom-6c34c7ec4d8f1c97.rlib,libderive_more-746200ced5662dd5.rlib,libserde-e0d783b46e19e3fc.rlib,libserde_core-dbf7f665be55c806.rlib,libflint_sys-6c439946d8f6a18d.rlib,liblibc-47d1a20e671dfc01.rlib,libthiserror-9192dc0b60f15726.rlib}.rlib" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib/{libstd-*,libpanic_unwind-*,libobject-*,libmemchr-*,libaddr2line-*,libgimli-*,librustc_demangle-*,libstd_detect-*,libhashbrown-*,librustc_std_workspace_alloc-*,libminiz_oxide-*,libadler2-*,libunwind-*,libcfg_if-*,liblibc-*,librustc_std_workspace_core-*,liballoc-*,libcore-*,libcompiler_builtins-*}.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-L" "/tmp/rustcVmuUbt/raw-dylibs" "-B<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/bin/gcc-ld" "-fuse-ld=lld" "-Wl,-znostart-stop-gc" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "/home/user/Documents/Rust/qfall-test/target/debug/build/alloca-40a57f704287e095/out" "-L" "/home/user/Documents/Rust/qfall-test/target/debug/build/flint-sys-f92676efbc0947e7/out/lib" "-L" "/home/user/Documents/Rust/qfall-test/target/debug/build/gmp-mpfr-sys-13218d66869abd60/out/lib" "-L" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/home/user/Documents/Rust/qfall-test/target/debug/deps/qfall_test-974396eae144f87a" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-nodefaultlibs"
  = note: some arguments are omitted. use `--verbose` to show all linker arguments     = note: rust-lld: error: relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC
          >>> defined in /home/user/Documents/Rust/qfall-test/target/debug/deps/libflint_sys-6c439946d8f6a18d.rlib(exception.o)                                                     >>> referenced by exception.c:55 (/var/home/user/Documents/Rust/index-calc/target/debug/build/flint-sys-f92676efbc0947e7/out/build/exception.c:55)                        >>>               exception.o:(flint_throw) in archive /home/user/Documents/Rust/qfall-test/target/debug/deps/libflint_sys-6c439946d8f6a18d.rlib                          
          rust-lld: error: relocation R_X86_64_32S cannot be used against local symbol; recompile with -fPIC
          >>> defined in /home/user/Documents/Rust/qfall-test/target/debug/deps/libflint_sys-6c439946d8f6a18d.rlib(exception.o)                                                     >>> referenced by exception.c:57 (/var/home/user/Documents/Rust/index-calc/target/debug/build/flint-sys-f92676efbc0947e7/out/build/exception.c:57)                        >>>               exception.o:(flint_throw) in archive /home/user/Documents/Rust/qfall-test/target/debug/deps/libflint_sys-6c439946d8f6a18d.rlib                          
          rust-lld: error: relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC
          >>> defined in /home/user/Documents/Rust/qfall-test/target/debug/deps/libflint_sys-6c439946d8f6a18d.rlib(memory_manager.o)                                                >>> referenced by memory_manager.c:51 (/var/home/user/Documents/Rust/index-calc/target/debug/build/flint-sys-f92676efbc0947e7/out/build/memory_manager.c:51)              >>>               memory_manager.o:(flint_memory_error) in archive /home/user/Documents/Rust/qfall-test/target/debug/deps/libflint_sys-6c439946d8f6a18d.rlib                                                                                                   rust-lld: error: relocation R_X86_64_32 cannot be used against symbol 'global_thread_pool'; recompile with -fPIC                                                          >>> defined in /home/user/Documents/Rust/qfall-test/target/debug/deps/libflint_sys-6c439946d8f6a18d.rlib(thread_pool_init.o)
          >>> referenced by memory_manager.c:233 (/var/home/user/Documents/Rust/index-calc/target/debug/build/flint-sys-f92676efbc0947e7/out/build/memory_manager.c:233)            >>>               memory_manager.o:(flint_cleanup_master) in archive /home/user/Documents/Rust/qfall-test/target/debug/deps/libflint_sys-6c439946d8f6a18d.rlib            
          rust-lld: error: relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC
          >>> defined in /home/user/Documents/Rust/qfall-test/target/debug/deps/libflint_sys-6c439946d8f6a18d.rlib(exception.o)
          >>> referenced by exception.c:72 (/var/home/user/Documents/Rust/index-calc/target/debug/build/flint-sys-f92676efbc0947e7/out/build/exception.c:72)                        >>>               exception.o:(flint_throw) in archive /home/user/Documents/Rust/qfall-test/target/debug/deps/libflint_sys-6c439946d8f6a18d.rlib                          
          rust-lld: error: relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC
          >>> defined in /home/user/Documents/Rust/qfall-test/target/debug/deps/libflint_sys-6c439946d8f6a18d.rlib(exception.o)
          >>> referenced by exception.c:78 (/var/home/user/Documents/Rust/index-calc/target/debug/build/flint-sys-f92676efbc0947e7/out/build/exception.c:78)
          >>>               exception.o:(flint_throw) in archive /home/user/Documents/Rust/qfall-test/target/debug/deps/libflint_sys-6c439946d8f6a18d.rlib
          
          rust-lld: error: relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC
          >>> defined in /home/user/Documents/Rust/qfall-test/target/debug/deps/libflint_sys-6c439946d8f6a18d.rlib(exception.o)
          >>> referenced by exception.c:60 (/var/home/user/Documents/Rust/index-calc/target/debug/build/flint-sys-f92676efbc0947e7/out/build/exception.c:60)
          >>>               exception.o:(flint_throw) in archive /home/user/Documents/Rust/qfall-test/target/debug/deps/libflint_sys-6c439946d8f6a18d.rlib
          
          rust-lld: error: relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC
          >>> defined in /home/user/Documents/Rust/qfall-test/target/debug/deps/libflint_sys-6c439946d8f6a18d.rlib(exception.o)
          >>> referenced by exception.c:63 (/var/home/user/Documents/Rust/index-calc/target/debug/build/flint-sys-f92676efbc0947e7/out/build/exception.c:63)
          >>>               exception.o:(flint_throw) in archive /home/user/Documents/Rust/qfall-test/target/debug/deps/libflint_sys-6c439946d8f6a18d.rlib
          
          rust-lld: error: relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC
          >>> defined in /home/user/Documents/Rust/qfall-test/target/debug/deps/libflint_sys-6c439946d8f6a18d.rlib(printf.o)
          >>> referenced by printf.c:77 (/var/home/user/Documents/Rust/index-calc/target/debug/build/flint-sys-f92676efbc0947e7/out/build/printf.c:77)
          >>>               printf.o:(flint_vprintf) in archive /home/user/Documents/Rust/qfall-test/target/debug/deps/libflint_sys-6c439946d8f6a18d.rlib
          
          rust-lld: error: relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC
          >>> defined in /home/user/Documents/Rust/qfall-test/target/debug/deps/libflint_sys-6c439946d8f6a18d.rlib(fmpz_divexact_ui.o)
          >>> referenced by divexact_ui.c:26 (/var/home/user/Documents/Rust/index-calc/target/debug/build/flint-sys-f92676efbc0947e7/out/build/fmpz/divexact_ui.c:26)
          >>>               fmpz_divexact_ui.o:(fmpz_divexact_ui) in archive /home/user/Documents/Rust/qfall-test/target/debug/deps/libflint_sys-6c439946d8f6a18d.rlib
          
          rust-lld: error: relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC
          >>> defined in /home/user/Documents/Rust/qfall-test/target/debug/deps/libflint_sys-6c439946d8f6a18d.rlib(exception.o)
          >>> referenced by exception.c:66 (/var/home/user/Documents/Rust/index-calc/target/debug/build/flint-sys-f92676efbc0947e7/out/build/exception.c:66)
          >>>               exception.o:(flint_throw) in archive /home/user/Documents/Rust/qfall-test/target/debug/deps/libflint_sys-6c439946d8f6a18d.rlib
          
          rust-lld: error: relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC
          >>> defined in /home/user/Documents/Rust/qfall-test/target/debug/deps/libflint_sys-6c439946d8f6a18d.rlib(exception.o)
          >>> referenced by exception.c:69 (/var/home/user/Documents/Rust/index-calc/target/debug/build/flint-sys-f92676efbc0947e7/out/build/exception.c:69)
          >>>               exception.o:(flint_throw) in archive /home/user/Documents/Rust/qfall-test/target/debug/deps/libflint_sys-6c439946d8f6a18d.rlib
          
          rust-lld: error: relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC
          >>> defined in /home/user/Documents/Rust/qfall-test/target/debug/deps/libflint_sys-6c439946d8f6a18d.rlib(printf.o)
          >>> referenced by printf.c:80 (/var/home/user/Documents/Rust/index-calc/target/debug/build/flint-sys-f92676efbc0947e7/out/build/printf.c:80)
          >>>               printf.o:(flint_vprintf) in archive /home/user/Documents/Rust/qfall-test/target/debug/deps/libflint_sys-6c439946d8f6a18d.rlib
          
          rust-lld: error: relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC
          >>> defined in /home/user/Documents/Rust/qfall-test/target/debug/deps/libflint_sys-6c439946d8f6a18d.rlib(exception.o)
          >>> referenced by exception.c:75 (/var/home/user/Documents/Rust/index-calc/target/debug/build/flint-sys-f92676efbc0947e7/out/build/exception.c:75)
          >>>               exception.o:(flint_throw) in archive /home/user/Documents/Rust/qfall-test/target/debug/deps/libflint_sys-6c439946d8f6a18d.rlib
          
          rust-lld: error: relocation R_X86_64_64 cannot be used against local symbol; recompile with -fPIC
          >>> defined in /home/user/Documents/Rust/qfall-test/target/debug/deps/libflint_sys-6c439946d8f6a18d.rlib(exception.o)
          >>> referenced by exception.c
          >>>               exception.o:(.rodata+0x0) in archive /home/user/Documents/Rust/qfall-test/target/debug/deps/libflint_sys-6c439946d8f6a18d.rlib
          
          rust-lld: error: relocation R_X86_64_64 cannot be used against local symbol; recompile with -fPIC
          >>> defined in /home/user/Documents/Rust/qfall-test/target/debug/deps/libflint_sys-6c439946d8f6a18d.rlib(exception.o)
          >>> referenced by exception.c
          >>>               exception.o:(.rodata+0x8) in archive /home/user/Documents/Rust/qfall-test/target/debug/deps/libflint_sys-6c439946d8f6a18d.rlib
          
          rust-lld: error: relocation R_X86_64_64 cannot be used against local symbol; recompile with -fPIC
          >>> defined in /home/user/Documents/Rust/qfall-test/target/debug/deps/libflint_sys-6c439946d8f6a18d.rlib(exception.o)
          >>> referenced by exception.c
          >>>               exception.o:(.rodata+0x10) in archive /home/user/Documents/Rust/qfall-test/target/debug/deps/libflint_sys-6c439946d8f6a18d.rlib
          
          rust-lld: error: relocation R_X86_64_64 cannot be used against local symbol; recompile with -fPIC
          >>> defined in /home/user/Documents/Rust/qfall-test/target/debug/deps/libflint_sys-6c439946d8f6a18d.rlib(exception.o)
          >>> referenced by exception.c
          >>>               exception.o:(.rodata+0x18) in archive /home/user/Documents/Rust/qfall-test/target/debug/deps/libflint_sys-6c439946d8f6a18d.rlib
          
          rust-lld: error: relocation R_X86_64_64 cannot be used against local symbol; recompile with -fPIC
          >>> defined in /home/user/Documents/Rust/qfall-test/target/debug/deps/libflint_sys-6c439946d8f6a18d.rlib(exception.o)
          >>> referenced by exception.c
          >>>               exception.o:(.rodata+0x20) in archive /home/user/Documents/Rust/qfall-test/target/debug/deps/libflint_sys-6c439946d8f6a18d.rlib
          
          rust-lld: error: relocation R_X86_64_64 cannot be used against local symbol; recompile with -fPIC
          >>> defined in /home/user/Documents/Rust/qfall-test/target/debug/deps/libflint_sys-6c439946d8f6a18d.rlib(exception.o)
          >>> referenced by exception.c
          >>>               exception.o:(.rodata+0x28) in archive /home/user/Documents/Rust/qfall-test/target/debug/deps/libflint_sys-6c439946d8f6a18d.rlib
          
          rust-lld: error: too many errors emitted, stopping now (use --error-limit=0 to see all errors)
          collect2: error: ld returned 1 exit status
          

error: could not compile `qfall-test` (bin "qfall-test") due to 1 previous error

Solution Possibly updating the flint_sys crate to be compiled with -fPIC but the suggestion could very well also be a red herring. Open to suggestions here as this could also just be an issue with my local system and not the library itself

gerblesh avatar Feb 05 '26 17:02 gerblesh

hmmm, building with the stable toolchain gives me less errors but still the same warning:

error: linking with `cc` failed: exit status: 1
  |
  = note:  "cc" "-m64" "/tmp/rustcw9GkH8/symbols.o" "<6 object files omitted>" "-Wl,--as-needed" "-Wl,-Bstatic" "/home/user/Documents/Rust/qfall-test/target/debug/deps/{libqfall_math-3ba0deffea848a4c.rlib,librand_distr-a02840d39a2a935e.rlib,libnum_traits-2727ee1611817f19.rlib,libregex-f923d7492446d544.rlib,libregex_automata-b14aa8b3236bb9c9.rlib,libaho_corasick-fbf11d74bae13ab8.rlib,libmemchr-1e9394a65a68f36c.rlib,libregex_syntax-c8298997d84b71f4.rlib,libstring_builder-c49c7f0a34d26cd5.rlib,librand-2a41c091772feabf.rlib,librand_chacha-93a4bb596cf849a7.rlib,libppv_lite86-f7bc021f24d049b2.rlib,libzerocopy-d565072ded69f0a3.rlib,librand_core-f4ce1ff479d9a0bc.rlib,libgetrandom-def2699c48d6cc55.rlib,libcfg_if-40a5137a037234b3.rlib,libprobability-23aa3b2a27042d83.rlib,libspecial-8ef2f67922dadc1e.rlib,liblibm-3cef1d7f6e48c432.rlib,librandom-29dbb63f6e2ee187.rlib,libderive_more-d90ee91d0a917458.rlib,libserde-20b6ebbd50b6990b.rlib,libserde_core-7c784f2201b7210b.rlib,libflint_sys-936f1bade903911b.rlib,liblibc-a360d92202790dad.rlib,libthiserror-219d92e6c7bc835a.rlib}.rlib" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib/{libstd-*,libpanic_unwind-*,libobject-*,libmemchr-*,libaddr2line-*,libgimli-*,librustc_demangle-*,libstd_detect-*,libhashbrown-*,librustc_std_workspace_alloc-*,libminiz_oxide-*,libadler2-*,libunwind-*,libcfg_if-*,liblibc-*,liballoc-*,librustc_std_workspace_core-*,libcore-*,libcompiler_builtins-*}.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-L" "/tmp/rustcw9GkH8/raw-dylibs" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "/home/user/Documents/Rust/qfall-test/target/debug/build/alloca-0f434d9ff33889be/out" "-L" "/home/user/Documents/Rust/qfall-test/target/debug/build/flint-sys-a21b2b7a79e27009/out/lib" "-L" "/home/user/Documents/Rust/qfall-test/target/debug/build/gmp-mpfr-sys-b21c50accf5d8867/out/lib" "-L" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/home/user/Documents/Rust/qfall-test/target/debug/deps/qfall_test-e637713c476090ba" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-nodefaultlibs"
  = note: some arguments are omitted. use `--verbose` to show all linker arguments
  = note: /usr/bin/ld: /home/user/Documents/Rust/qfall-test/target/debug/deps/libflint_sys-936f1bade903911b.rlib(printf.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIE
          /usr/bin/ld: failed to set dynamic section sizes: bad value
          collect2: error: ld returned 1 exit status


error: could not compile `qfall-test` (bin "qfall-test") due to 1 previous error

gerblesh avatar Feb 05 '26 18:02 gerblesh

I am not quite sure yet on what the issue could be. flint-sys itself is compiled using -fPIC, so I think it is something else (https://github.com/search?q=repo%3Aalex-ozdemir%2Fflint-rs%20-fPIC&type=code)

Marvin-Beckmann avatar Feb 06 '26 07:02 Marvin-Beckmann

in your example, do you have flint-sys and qfall-math or only qfall-math in your dependencies?

Marvin-Beckmann avatar Feb 06 '26 07:02 Marvin-Beckmann

Which underlying architecture does your PC have? 32-bit or 64-bit? I think we only ever tried it with 64-bit architectures.

Marvin-Beckmann avatar Feb 06 '26 08:02 Marvin-Beckmann

in your example, do you have flint-sys and qfall-math or only qfall-math in your dependencies?

in the example, just qfall-math. I use a AMD64 CPU, I'm on a fairly modern distro (Fedora 43). I saw that in the docs there's some fix that's needed for modern distros, does that apply here?

gerblesh avatar Feb 06 '26 16:02 gerblesh

I think I have an idea as to what it could be..

We are currently not using the most recent version of FLINT. When FLINT transitioned from FLINT2 to FLINT3, they reworked their build system (now using autotools: https://groups.google.com/g/flint-devel/c/pDVgut-EOoI). The old build system was likely not automated in the same way and might have some code snippets where explicit addresses are used, which could cause problems when compiling it with -fPIC, as in: it is not transforming it correctly. From what I can find, Fedora 43 seems to be a lot stricter than Ubuntu (where I tried it mostly) when enforcing the explicit rules regarding PIE.

So it seems to be an inherent problem of us using FLINT2 at the moment. There is a crate called flint3-sys (https://crates.io/crates/flint3-sys) that was published towards the end of last year separately from flint-sys, but we have not evaluated how exactly we plan to update to FLINT3 yet.

I have some hope that switching to FLINT3 resolves this issue.

Marvin-Beckmann avatar Feb 09 '26 09:02 Marvin-Beckmann

Thanks for looking into this! I ended up using a different library but I'll keep an eye on qfall for any future projects

gerblesh avatar Feb 09 '26 18:02 gerblesh