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

JIT unable to find symbols from libc_nonshared.a #61289

Open
hahnjo opened this issue Mar 9, 2023 · 6 comments
Open

JIT unable to find symbols from libc_nonshared.a #61289

hahnjo opened this issue Mar 9, 2023 · 6 comments
Labels

Comments

@hahnjo
Copy link
Member

hahnjo commented Mar 9, 2023

Right now, the JIT seems to be unable to find symbols from the static libc_nonshared.a, that is linked together with libc.so. Until ~2020, this library contained a number of wrappers, including the *stat functions. On these systems, for example EL 8 but also not-latest Ubuntus, the following C code:

#include <sys/stat.h>

int main() {
  struct stat s;
  lstat("build.ninja", &s);
  return 0;
}

when compiled into IR and then fed to lli fails with:

JIT session error: Symbols not found: [ lstat ]
./bin/lli: Failed to materialize symbols: { (main, { main }) }

The good news is that recent glibc heavily reduced the number of symbols in that static library, up to the point that it only contains at_quick_exit, atexit, pthread_atfork, and __stack_chk_fail_local. It would be nice to improve the situation for older systems, but not sure if we can do much about it...

@hahnjo hahnjo added the orcjit label Mar 9, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Mar 9, 2023

@llvm/issue-subscribers-orcjit

@lhames
Copy link
Contributor

lhames commented Mar 10, 2023

@hahnjo Have you tried adding a StaticLibraryDefinitionGenerator for libc_nonshared.a? If the functions that you mentioned aren't linked and exported in your binary then the right thing to do is add the archive to your JITDylib and let the JIT pull them in.

@hahnjo
Copy link
Member Author

hahnjo commented Mar 10, 2023

Yes perfect, adding --extra-archive=/usr/lib64/libc_nonshared.a to the command line works! Should this be the default in LLJIT?

@lhames
Copy link
Contributor

lhames commented Mar 10, 2023

I think so. I think we want some sort of "add standard runtimes" utility, probably as part of SetUpExecutorNativePlatform in https://reviews.llvm.org/D144276. This could pull in compiler-rt and the MSVC runtime too.

We'd need to get he behavior right, e.g. what library search order should it use on each platform, and what should it do if a library is not found?

We could always starting experimenting with the idea in the lli tool itself --the stakes are lower there.

hahnjo added a commit to hahnjo/root that referenced this issue Jul 19, 2023
This symbol may be in libc_nonshared.a where symbols are not found
automatically. See also upstream issue
llvm/llvm-project#61289. This fixes the
test DynamicLibraryManager/cached_realpath.C.
hahnjo added a commit to hahnjo/root that referenced this issue Jul 19, 2023
This symbol may be in libc_nonshared.a where symbols are not found
automatically. See also upstream issue
llvm/llvm-project#61289. This fixes the
test DynamicLibraryManager/cached_realpath.C, approach by Lang Hames.
@lhames
Copy link
Contributor

lhames commented Jul 19, 2023

I chatted to @vgvassilev a little more about this on discord.

Adding the static archives to the JITDylib is the fully general solution: it will handle archives that have static constructors and destructors, etc.

I suspect that 99% of the time this is overkill, and it's sufficient to point these symbols at copies linked into the main executable, and that's what we've been living on for years. For in-process JITs it's sufficient to define absoluteSymbols pointing at the desired functions, but this won't work for out-of-process JITs. For the out-of-process case we can solve this once we have a pre-linked ORC runtime library: we can add a get_libc_workaround_symbols function to that which returns a mapping that can be added to the JIT in the controller process.

I'll leave this open for now to track the idea discussed above: having the platform (or SetUpExecutorNativePlatform utility) set up the archive automatically.

hahnjo added a commit to hahnjo/root that referenced this issue Jul 20, 2023
These symbols may not be found automatically. See also upstream issue
llvm/llvm-project#61289. This fixes the
test DynamicLibraryManager/cached_realpath.C, approach by Lang Hames.
hahnjo added a commit to root-project/root that referenced this issue Jul 21, 2023
These symbols may not be found automatically. See also upstream issue
llvm/llvm-project#61289. This fixes the
test DynamicLibraryManager/cached_realpath.C, approach by Lang Hames.
@hahnjo
Copy link
Member Author

hahnjo commented Jul 21, 2023

Thanks Lang, we've now implemented a workaround using absoluteSymbols in ROOT/Cling: root-project/root#13286

FonsRademakers pushed a commit to root-project/cling that referenced this issue Jul 21, 2023
These symbols may not be found automatically. See also upstream issue
llvm/llvm-project#61289. This fixes the
test DynamicLibraryManager/cached_realpath.C, approach by Lang Hames.
hahnjo added a commit to hahnjo/root that referenced this issue Jul 25, 2023
These symbols may not be found automatically. See also upstream issue
llvm/llvm-project#61289. This fixes the
test DynamicLibraryManager/cached_realpath.C, approach by Lang Hames.

(cherry picked from commit 4b6075b)
hahnjo added a commit to root-project/root that referenced this issue Jul 26, 2023
These symbols may not be found automatically. See also upstream issue
llvm/llvm-project#61289. This fixes the
test DynamicLibraryManager/cached_realpath.C, approach by Lang Hames.

(cherry picked from commit 4b6075b)
maksgraczyk pushed a commit to maksgraczyk/root that referenced this issue Jan 12, 2024
These symbols may not be found automatically. See also upstream issue
llvm/llvm-project#61289. This fixes the
test DynamicLibraryManager/cached_realpath.C, approach by Lang Hames.
LebedevRI added a commit to LebedevRI/Halide that referenced this issue Aug 11, 2024
The original workaround is very partial,
and was not really working in my experience,
even after making it non-GCC specific.

Instead:
1. Ensure that the library that actually provides that symbol
   (as per the compiler used!) is actually linked into.
   This was not enough still.
2. Replace `HalideJITMemoryManager` hack with a more direct approach
   of actually telling the JIT the address of the symbol.
3. While there, move the symbol's forward definition to outside
   of namespaces. It's a global symbol, it makes sense to place it there.

This makes python binding tests pass on i386,
and i'm really happy about that.

Refs. llvm/llvm-project#61289
Inspired by root-project/root#13286
LebedevRI added a commit to LebedevRI/Halide that referenced this issue Aug 11, 2024
The original workaround is very partial,
and was not really working in my experience,
even after making it non-GCC specific.

Instead:
1. Ensure that the library that actually provides that symbol
   (as per the compiler used!) is actually linked into.
   This was not enough still.
2. Replace `HalideJITMemoryManager` hack with a more direct approach
   of actually telling the JIT the address of the symbol.
3. While there, move the symbol's forward definition to outside
   of namespaces. It's a global symbol, it makes sense to place it there.

This makes python binding tests pass on i386,
and i'm really happy about that.

Refs. llvm/llvm-project#61289
Inspired by root-project/root#13286
LebedevRI added a commit to LebedevRI/Halide that referenced this issue Aug 11, 2024
The original workaround is very partial,
and was not really working in my experience,
even after making it non-GCC specific.

Instead:
1. Ensure that the library that actually provides that symbol
   (as per the compiler used!) is actually linked into.
   This was not enough still.
2. Replace `HalideJITMemoryManager` hack with a more direct approach
   of actually telling the JIT the address of the symbol.
3. While there, move the symbol's forward definition to outside
   of namespaces. It's a global symbol, it makes sense to place it there.

This makes python binding tests pass on i386,
and i'm really happy about that.

Refs. llvm/llvm-project#61289
Inspired by root-project/root#13286
LebedevRI added a commit to LebedevRI/Halide that referenced this issue Aug 11, 2024
The original workaround is very partial,
and was not really working in my experience,
even after making it non-GCC specific.

Instead:
1. Ensure that the library that actually provides that symbol
   (as per the compiler used!) is actually linked into.
   This was not enough still.
2. Replace `HalideJITMemoryManager` hack with a more direct approach
   of actually telling the JIT the address of the symbol.
3. While there, move the symbol's forward definition to outside
   of namespaces. It's a global symbol, it makes sense to place it there.

This makes python binding tests pass on i386,
and i'm really happy about that.

Refs. llvm/llvm-project#61289
Inspired by root-project/root#13286
LebedevRI added a commit to LebedevRI/Halide that referenced this issue Aug 11, 2024
The original workaround is very partial,
and was not really working in my experience,
even after making it non-GCC specific.

Instead:
1. Ensure that the library that actually provides that symbol
   (as per the compiler used!) is actually linked into.
   This was not enough still.
2. Replace `HalideJITMemoryManager` hack with a more direct approach
   of actually telling the JIT the address of the symbol.
3. While there, move the symbol's forward definition to outside
   of namespaces. It's a global symbol, it makes sense to place it there.

This makes python binding tests pass on i386,
and i'm really happy about that.

Refs. llvm/llvm-project#61289
Inspired by root-project/root#13286

Forwarded: halide#8389

Gbp-Pq: Name 0010-JITModule-rework-fix-__udivdi3-handling.patch
LebedevRI added a commit to LebedevRI/Halide that referenced this issue Aug 13, 2024
The original workaround is very partial,
and was not really working in my experience,
even after making it non-GCC specific.

Instead:
1. Ensure that the library that actually provides that symbol
   (as per the compiler used!) is actually linked into.
   This was not enough still.
2. Replace `HalideJITMemoryManager` hack with a more direct approach
   of actually telling the JIT the address of the symbol.
3. While there, move the symbol's forward definition to outside
   of namespaces. It's a global symbol, it makes sense to place it there.

This makes python binding tests pass on i386,
and i'm really happy about that.

Refs. llvm/llvm-project#61289
Inspired by root-project/root#13286

Forwarded: halide#8389

Gbp-Pq: Name 0010-JITModule-rework-fix-__udivdi3-handling.patch
LebedevRI added a commit to LebedevRI/Halide that referenced this issue Aug 13, 2024
The original workaround is very partial,
and was not really working in my experience,
even after making it non-GCC specific.

Instead:
1. Ensure that the library that actually provides that symbol
   (as per the compiler used!) is actually linked into.
   This was not enough still.
2. Replace `HalideJITMemoryManager` hack with a more direct approach
   of actually telling the JIT the address of the symbol.
3. While there, move the symbol's forward definition to outside
   of namespaces. It's a global symbol, it makes sense to place it there.

This makes python binding tests pass on i386,
and i'm really happy about that.

Refs. llvm/llvm-project#61289
Inspired by root-project/root#13286

Forwarded: halide#8389

Gbp-Pq: Name 0010-JITModule-rework-fix-__udivdi3-handling.patch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants