[flang-commits] [flang] [clang] [Flang][Driver] Enable gpulibc/nogpulibc options for Flang, which allows linking of GPU LIBC for the fortran and OpenMP runtime (PR #77135)

Joseph Huber via flang-commits flang-commits at lists.llvm.org
Fri Jan 5 12:48:09 PST 2024


jhuber6 wrote:

> I am gonna sign off for the weekend as it's quite late here, so I'll reply in a little more detail on Monday and update the PR further. but I'd be happy to add a further flang test, although not too sure what it'd be, so suggestions are welcome.
> 
> I tested this with an out of tree build of GPU libc (basically two seperate build directories) and found that -lgpuc wouldn't get the ordering correct to link the library correctly to the fortran runtime, so it seemed for this specific case of an out of tree build of GPU libc the option was the correct way to get it linked in in the correct order. In the case of it finding it in the correct directory i didn't quite manage the perfect build recipe for it (suggestions welcome here as well) and tend to not use the install option myself, but perhaps it would auto detect for Flang as well! However, in the case where it's an separately compiled and installed gpu libc it might be nice to have this option activated as well for Flang to make both methods of linking possible. However, i am a little bit of a driver and build environment/system noob so ill defer to everyone else's better judgement in this case!

If you have the static library, and it contains an entry for the desired architecture, it should just work so long as you're using the "new" driver pipeline. However, ordering is important here. It behaves similarly to the GNU BFD linker, where a static library is only checked against the current state of the symbol table as it reads the files in input order. So `uses.o -lfoo` will extract but `-lfoo uses.o` will not.

It's possible that this just was being linked too late with however Fortran handles it. I decided to be conservative with the default here because I'm assuming very few people will actually have the GPU `libc`. 

It would be very interesting to see something like `puts` working from Fortran, so let me know if there's anything I can do to help.

https://github.com/llvm/llvm-project/pull/77135


More information about the flang-commits mailing list