Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

glibc2.36 adds arc4random_buf, causing compile error #33

Closed
kwshi opened this issue Jan 16, 2023 · 6 comments · Fixed by #35
Closed

glibc2.36 adds arc4random_buf, causing compile error #33

kwshi opened this issue Jan 16, 2023 · 6 comments · Fixed by #35

Comments

@kwshi
Copy link

kwshi commented Jan 16, 2023

Per https://sourceware.org/glibc/wiki/Release/2.36, glibc2.36 adds built-in declarations for arc4random_buf. When compiling this library as dependency for another project (ghcup), the arc4random_buf declaration from this project (in c/archive_random.c) clashes with the built-in declaration, resulting in an error message like so:

[15 of 15] Compiling Codec.Archive    ( src/Codec/Archive.hs, dist/build/Codec/Archive.o, dist/build/Codec/Archive.dyn_o )

c/archive_random.c:54:13: error:
     error: static declaration of 'arc4random_buf' follows non-static declaration
       54 | static void arc4random_buf(void *, size_t);
          |             ^~~~~~~~~~~~~~
   |
54 | static void arc4random_buf(void *, size_t);
   |             ^

In file included from c/archive_random.c:30:0: error:

/usr/include/stdlib.h:542:13: error:
     note: previous declaration of 'arc4random_buf' with type 'void(void *, size_t)' {aka 'void(void *, long unsigned int)'}
      542 | extern void arc4random_buf (void *__buf, size_t __size)
          |             ^~~~~~~~~~~~~~
    |
542 | extern void arc4random_buf (void *__buf, size_t __size)
    |             ^
`cc' failed in phase `C Compiler'. (Exit code: 1)
cabal: Failed to build libarchive-3.0.3.2 (which is required by exe:ghcup from
ghcup-0.1.19.0). See the build log above for details.

The command being used to build ghcup (released version v0.1.19.0) is:

cabal build --prefix=. --project-file=cabal.project -f+internal-downloader -f+tui -f+system-libarchive

(from some testing, this error occurs regardless of whether -f+system-libarchive is passed).

I see that there is some way of customizing whether to include this declaration, perhaps by setting HAVE_ARC4RANDOM_BUF in autoconf-linux/config.h; however I have no idea how to correctly customize this config when the library is being built automatically by Cabal, as dependency of a different project. Would releasing a new version of this library to be compatible with glibc2.36 help?

@hasufell
Copy link
Collaborator

-f+system-libarchive

I'm pretty certain the library builds with this. I have the same error on Fedora 37 and can build with system libarchive.

Wrt the bug, yeah, I'm not even sure what's the right fix.

@kwshi
Copy link
Author

kwshi commented Jan 16, 2023

I'm pretty certain the library builds with this. I have the same error on Fedora 37 and can build with system libarchive.

I'm running the following script on my machine (VoidLinux, glibc 2.36) from a fresh directory:

#!/bin/bash
curl -L 'https://github.com/haskell/ghcup-hs/archive/refs/tags/v0.1.19.0.tar.gz' \
  | tar -xz

cd 'ghcup-hs-0.1.19.0'
cabal build --prefix='.' --project='cabal.project' \
  -f'+internal-downloader' -f'+tui' -f'+system-libarchive'

This exact build command is giving me the arc4random_buf error. That doesn't happen for you? Perhaps I'm invoking cabal wrong or something? Or our cabals behave differently? (I'm on Cabal 3.6.2.0). If you still can't reproduce the error, I'll try writing a Dockerfile to reproduce shortly.

@hasufell
Copy link
Collaborator

-f+foo is somewhat broken sometimes. Try --constraint='libarchive +system-libarchive'.

@kwshi
Copy link
Author

kwshi commented Jan 16, 2023

Running

cabal build --prefix='.' --project='cabal.project' \
  --constraint='libarchive +system-libarchive'

now gives

Resolving dependencies...
cabal: Could not resolve dependencies:
[__0] trying: ghcup-0.1.19.0 (user goal)
[__1] trying: libarchive-3.0.3.2 (dependency of ghcup)
[__2] rejecting: libarchive:+system-libarchive (constraint from config file,
command line flag, or user target requires opposite flag selection)
[__2] rejecting: libarchive:-system-libarchive (constraint from command line
flag requires opposite flag selection)
[__2] fail (backjumping, conflict set: libarchive,
libarchive:system-libarchive)
After searching the rest of the dependency tree exhaustively, these were the
goals I've had most trouble fulfilling: ghcup, libarchive,
libarchive:system-libarchive

It looks like cabal.project explicitly specifies -system-libarchive, and --constraint attempts to satisfy both rather than override the flag defined in cabal.project. However, it seems patching cabal.project with the +system-libarchive flag does help it build correctly.

@daapp
Copy link

daapp commented May 23, 2023

Removing

package libarchive
  flags: -system-libarchive

from cabal.project and build using cabal build --prefix=. --project-file=cabal.project -f+internal-downloader -f+tui --constraint='libarchive +system-libarchive' will solve this problem

@hasufell
Copy link
Collaborator

The issue is here:

/* Define to 1 if you have the `arc4random_buf' function. */
/* #undef HAVE_ARC4RANDOM_BUF */

We would have to migrate to an autoconf script that produces a proper config.h on the target system instead of bundling that config. That would complicate the libarchive build system though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants