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

Don't hard-code -ldl -lpthread for format_args #2890

Open
tschwinge opened this issue Feb 28, 2024 · 4 comments
Open

Don't hard-code -ldl -lpthread for format_args #2890

tschwinge opened this issue Feb 28, 2024 · 4 comments
Labels
misc upstream Issue regarding upstreaming gccrs into GCC

Comments

@tschwinge
Copy link
Member

As of #2822 "Start reusing rustc's format_args parser", we add -ldl -lpthread to LIBS in gcc/rust/Make-lang.in. Instead of doing this unconditionally, we should check if those libraries exist at all, and which are actually necessary -- query Cargo about crate's linker flags?

@CohenArthur
Copy link
Member

note that this was done exclusively because the build was breaking in our GCC 4.8 CI - other contributors on IRC have mentioned the existence of flags/autoconf functions to check for the existence/necessity of these libraries, so any help would be greatly appreciated

@tschwinge
Copy link
Member Author

Cross-referencing https://gcc.gnu.org/PR113499 "crab1 fails to link when configuring with --disable-plugin" here.

@CohenArthur CohenArthur added the upstream Issue regarding upstreaming gccrs into GCC label Mar 26, 2024
@tschwinge
Copy link
Member Author

If "query Cargo about crate's linker flags" is not feasible (at this time, at least), then indeed I think I'd add a simple check whether *.so exist (that is, can be linked via a dummy Autoconf stanza -- or is there even a AC_[...] to check for libraries' existence?), and if yes, then link crab1 against those unconditionally.

@CohenArthur
Copy link
Member

some notes from discussing this with jakub:

            │18:20:52        jakub │ cohenarthur1: depends on what you want to test; if it is just test whether "do I need to link with -ldl if I use dlopen or not" or "do I need to link with -lpthread or -pthread if I use pthread_create or not", then │ nathanchance
            │                      │ yes, adding similar configure.ac checks and using it in Makefile.in/make fragments will be enough; but if you need to somehow handle the case where hosts doesn't have pthread                                         │ ndesaulniers
            │18:20:54        jakub │ at all and either just silently should have rust not configured in on --enable-languages=all, or have some nice error than <pthread.h>, no such header or similar, then more work is needed                            │ Nebraskka
            │18:21:18        jakub │ as for not using @DL_LIB@ anywhere, no idea, you'd need to ask the folks which added it to configure.ac (see git blame)                                                                                                │ nightstrike
            │18:22:06 cohenarthur1 │ ah, fair - since you were the one talking about it I assumed it was your addition :) thanks for the help                                                                                                               │ noteness
            │18:23:49        jakub │ note, I think the current configure.ac test for DL_LIB actually doesn't check if you can use dlopen without linking -ldl; so in the recent glibc or Darwin case, it might be better try to link a program using        │ nrubsig
            │                      │ #include <dlfcn.h> and using dlopen, dlsym, dlclose without -ldl, if that works, set DL_LIB or whatever to nothing, otherwise try to link with -ldl, if that works, set DL_LIB to                                      │ ogabbay__
            │18:23:52        jakub │ -ldl, otherwise if neither works, do something reasonable (error out if rust is configured, ...)  

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
misc upstream Issue regarding upstreaming gccrs into GCC
Projects
None yet
Development

No branches or pull requests

2 participants