This is an archive of the discontinued LLVM Phabricator instance.

[clang-repl] Adapt to the recent dylib-related changes in ORC.
ClosedPublic

Authored by v.g.vassilev on Aug 29 2023, 8:41 AM.

Details

Summary

ORC splits into separate dylibs symbols coming from the process and symbols materialized in the Jit. This patch adapts intent of the existing interface and adds a regression test to make sure both Jit'd and compiled symbols can be found.

Diff Detail

Event Timeline

v.g.vassilev created this revision.Aug 29 2023, 8:41 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 29 2023, 8:41 AM
v.g.vassilev requested review of this revision.Aug 29 2023, 8:41 AM
lhames accepted this revision.Aug 29 2023, 8:59 AM

Otherwise LGTM!

clang/lib/Interpreter/IncrementalExecutor.cpp
96–100

I think this should be equivalent to

auto SO =
  makeJITDylibSearchFlags(&Jit->getMainJITDylib(),
                          Jit->getPlatformJITDylib().get(),
                          Jit->getProcessSymbolsJITDylib.get());

but this is purely cosmetic -- either way works.

This revision is now accepted and ready to land.Aug 29 2023, 8:59 AM

Address review comment.

v.g.vassilev marked an inline comment as done.

Address style comment.

This revision was landed with ongoing or failed builds.Aug 29 2023, 12:20 PM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptAug 29 2023, 12:20 PM
mgorny added a subscriber: mgorny.Sep 5 2023, 2:36 AM

This change is causing test regressions on 32-bit architectures (I've reproduced with -m32 on amd64 and in 32-bit nspawn container on arm64):

FAIL: Clang-Unit :: Interpreter/./ClangReplInterpreterTests/1/13 (1 of 1584)
******************** TEST 'Clang-Unit :: Interpreter/./ClangReplInterpreterTests/1/13' FAILED ********************
Script(shard):
--
GTEST_OUTPUT=json:/home/mgorny/llvm-project/build/tools/clang/unittests/Interpreter/./ClangReplInterpreterTests-Clang-Unit-1816215-1-13.json GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=13 GTEST_SHARD_INDEX=1 /home/mgorny/llvm-project/build/tools/clang/unittests/Interpreter/./ClangReplInterpreterTests
--

Script:
--
/home/mgorny/llvm-project/build/tools/clang/unittests/Interpreter/./ClangReplInterpreterTests --gtest_filter=IncrementalProcessing.FindMangledNameSymbol
--
/home/mgorny/llvm-project/clang/unittests/Interpreter/InterpreterTest.cpp:246: Failure
Expected equality of these values:
  (unsigned long long)&printf
    Which is: 18446744073567794308
  Addr->getValue()
    Which is: 4153209988

/home/mgorny/llvm-project/clang/unittests/Interpreter/InterpreterTest.cpp:246
Expected equality of these values:
  (unsigned long long)&printf
    Which is: 18446744073567794308
  Addr->getValue()
    Which is: 4153209988


********************
mgorny added a comment.Sep 5 2023, 7:54 AM

Changing the type from unsigned long long to uintptr_t fix the test for me.

clang/unittests/Interpreter/InterpreterTest.cpp
246

Changing the type from unsigned long long to uintptr_t fix the test for me.

Ah! Nice catch! Can you commit the fix?

Changing the type from unsigned long long to uintptr_t fix the test for me.

Ah! Nice catch! Can you commit the fix?

Done, thanks to @mgorny for the testing and thank you @v.g.vassilev for the quick ack!

mgorny added a comment.Sep 5 2023, 8:16 AM

Thank you both!

tuliom added a subscriber: tuliom.Sep 6 2023, 11:19 AM
tuliom added a comment.Sep 6 2023, 1:50 PM

This new test does not work on ppc64le.
The returned addresses are different:

Expected equality of these values:
  (uintptr_t)&printf
    Which is: 140735424286016
  Addr->getValue()
    Which is: 140735424167152
mgorny added a comment.Sep 6 2023, 8:19 PM

This new test does not work on ppc64le.

I'm sorry, by "new" you mean the version with uintptr_t or the original as well?

mgorny added a comment.Sep 8 2023, 4:22 AM

This new test does not work on ppc64le.

I've tested right now (as of 3398744a6106c83993611bd3c5e79ec6b94417dc) and all clang tests passed for me on Gentoo/ppc64le.

tuliom added a comment.Sep 8 2023, 6:25 AM

I'm sorry, by "new" you mean the version with uintptr_t or the original as well?

Both with uintptr_t as well as unsigned long long.

I've tested right now (as of 3398744a6106c83993611bd3c5e79ec6b94417dc) and all clang tests passed for me on Gentoo/ppc64le.

Did Gentoo switch the default long double to IEEE 128-bit floating point?
If not, that could explain why this new code is broken on ppc64le.

tuliom added a comment.Sep 8 2023, 7:02 AM

Let me elaborate my previous comment...
I'm using Fedora, which has switched the default long double on ppc64le to IEEE 128-bit floating point.
glibc provides 2 printf implementations on ppc64le (different symbols). The headers control which implementation is used.

I wonder if the Jit is taking the right symbol.

mgorny added a comment.Sep 8 2023, 7:09 AM

Did Gentoo switch the default long double to IEEE 128-bit floating point?

LDBL_MANT_DIG is 106, so I guess not yet on this system.

glibc provides 2 printf implementations on ppc64le (different symbols). The headers control which implementation is used.

Is that actually a regression, or merely the test wasn't checking it before? My educated guess would be that the code in the test redefines printf without the header mangling, so it finds and compares the "non-IEEE" symbol against the "IEEE" symbol that's exposed to the test case via the headers.

Is that actually a regression, or merely the test wasn't checking it before?

I can't tell because the test didn't exist before.

My educated guess would be that the code in the test redefines printf without the header mangling, so it finds and compares the "non-IEEE" symbol against the "IEEE" symbol that's exposed to the test case via the headers.

I agree with you.

Is that actually a regression, or merely the test wasn't checking it before?

I can't tell because the test didn't exist before.

My educated guess would be that the code in the test redefines printf without the header mangling, so it finds and compares the "non-IEEE" symbol against the "IEEE" symbol that's exposed to the test case via the headers.

I agree with you.

Would that be a problem with the RuntimeDyld part of the JIT on ppc64le? Maybe @lkail could help us sort it out?

cc: @lhames