This is an archive of the discontinued LLVM Phabricator instance.

[lldb][Android] Use a lambda for calls to ::open in RetryAfterSignal
ClosedPublic

Authored by splhack on Jun 12 2023, 8:49 AM.

Details

Summary

lldb-server for Android does not build with NDK r21 and above due to
RetryAfterSignal and Bionic ::open mismatch.
https://github.com/llvm/llvm-project/issues/54727

Apply the LLVM patch to LLDB.
https://github.com/llvm/llvm-project/commit/0a0e411204a2baa520fd73a8d69b664f98b428ba

In Bionic, open can be overloaded for _FORTIFY_SOURCE support, causing
compile errors of RetryAfterSignal due to overload resolution. Wrapping
the call in a lambda avoids this.

Diff Detail

Event Timeline

splhack created this revision.Jun 12 2023, 8:49 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 12 2023, 8:49 AM
Herald added a subscriber: danielkiss. · View Herald Transcript
splhack published this revision for review.Jun 12 2023, 9:00 AM
splhack added reviewers: clayborg, hans.
Herald added a project: Restricted Project. · View Herald TranscriptJun 12 2023, 9:01 AM
hans edited reviewers, added: labath; removed: hans.Jun 13 2023, 4:56 AM

+labath

bulbazord accepted this revision.Jun 13 2023, 3:12 PM
bulbazord added a subscriber: bulbazord.

I don't really work on android-related code anymore but this change seems alright to me. There's prior art in LLVM which makes it a lot easier to accept. It's unfortunate that we need this workaround because of an issue with Bionic, but that's life.

You may want to wait until another person has a chance to look at this though.

This revision is now accepted and ready to land.Jun 13 2023, 3:12 PM
yinghuitan accepted this revision.Jun 13 2023, 8:22 PM
yinghuitan added a subscriber: yinghuitan.

Can we wrap this as a helper function and shared to avoid duplication? Otherwise looks good.

splhack updated this revision to Diff 531186.Jun 13 2023, 10:51 PM

Add lldb/include/lldb/Host/common/RetryAfterSignal.h

@yinghuitan yup, RetryAfterSignal::Open helper functions look better.

splhack updated this revision to Diff 531381.Jun 14 2023, 9:29 AM

rebase onto main

JDevlieghere requested changes to this revision.Jun 14 2023, 11:07 AM

Should we make this the default behavior in FileSystem? Either way I think this belongs there rather than in Host.

This revision now requires changes to proceed.Jun 14 2023, 11:07 AM

@JDevlieghere does FileSystem::RetryAfterSignal::Open sound good to you?
Or FileSystem::RetryAfterSignalOpen?

oh wait, FileSystem::Open is already RetryAfterSignal::Open in this diff.
will replace RetryAfterSignal::Open with FileSystem::Open.

splhack updated this revision to Diff 531483.Jun 14 2023, 1:26 PM

Replace llvm::sys::RetryAfterSignal(-1, ::open) with
FileSystem::Instance().Open.

JDevlieghere accepted this revision.Jun 14 2023, 4:57 PM

Nice. LGTM.

This revision is now accepted and ready to land.Jun 14 2023, 4:57 PM

Hi. I think this is leading to the lldb test failures we're seeing on our linux builder (https://logs.chromium.org/logs/fuchsia/buildbucket/cr-buildbucket/8778187770933863505/+/u/lldb/test/stdout?format=raw):

********************
FAIL: lldb-unit :: Host/./HostTests/13/39 (1722 of 2262)
******************** TEST 'lldb-unit :: Host/./HostTests/13/39' FAILED ********************
Script(shard):
--
GTEST_OUTPUT=json:/b/s/w/ir/x/w/staging/llvm_build/tools/lldb/unittests/Host/./HostTests-lldb-unit-1483998-13-39.json GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=39 GTEST_SHARD_INDEX=13 /b/s/w/ir/x/w/staging/llvm_build/tools/lldb/unittests/Host/./HostTests
--

Note: This is test shard 14 of 39.
[==========] Running 2 tests from 2 test suites.
[----------] Global test environment set-up.
[----------] 1 test from File
[ RUN      ] File.GetWaitableHandleFileno
[       OK ] File.GetWaitableHandleFileno (1 ms)
[----------] 1 test from File (1 ms total)

[----------] 1 test from TerminalTest
[ RUN      ] TerminalTest.SetRaw
/b/s/w/ir/x/w/cipd/bin/../include/c++/v1/optional:1023: assertion this->has_value() failed: optional operator* called on a disengaged value#0 0x0000560219fba7a8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/b/s/w/ir/x/w/staging/llvm_build/tools/lldb/unittests/Host/./HostTests+0x1417a8)

--
exit: -6
--
shard JSON output does not exist: /b/s/w/ir/x/w/staging/llvm_build/tools/lldb/unittests/Host/./HostTests-lldb-unit-1483998-13-39.json
********************

Would you be able to send a fix or revert? Thanks.

@leonardchan yes, I'm looking into. -6 is ENXIO? Is it using POSIX code path? Is it possible to see symbolicated stack trace of the crash?

found symbolicated stack trace in
https://lab.llvm.org/buildbot/#/builders/96/builds/40769/steps/6/logs/stdio

TerminalTest does not instantiate FileSystem. now preparing to submit a diff to fix it.

 #0 0x0000aaaacc46d6d4 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb/unittests/Host/./HostTests+0xa06d4)
 #1 0x0000aaaacc46bc08 llvm::sys::RunSignalHandlers() (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb/unittests/Host/./HostTests+0x9ec08)
 #2 0x0000aaaacc46df78 SignalHandler(int) Signals.cpp:0:0
 #3 0x0000ffffb0a38598 (linux-vdso.so.1+0x598)
 #4 0x0000ffffb023f200 __pthread_kill_implementation ./nptl/./nptl/pthread_kill.c:44:76
 #5 0x0000ffffb01fa67c gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #6 0x0000ffffb01e7130 abort ./stdlib/./stdlib/abort.c:81:7
 #7 0x0000aaaacc3f62e4 testing::AssertionResult testing::internal::CmpHelperEQ<lldb_private::URI, lldb_private::URI>(char const*, char const*, lldb_private::URI const&, lldb_private::URI const&) (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb/unittests/Host/./HostTests+0x292e4)
 #8 0x0000aaaacc4bb1d0 lldb_private::FileSystem::Instance() (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb/unittests/Host/./HostTests+0xee1d0)
 #9 0x0000aaaacc4c3f18 lldb_private::PseudoTerminal::OpenSecondary(int) (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb/unittests/Host/./HostTests+0xf6f18)
#10 0x0000aaaacc45304c TerminalTest::SetUp() crtstuff.c:0:0
#11 0x0000aaaacc48bccc testing::Test::Run() (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb/unittests/Host/./HostTests+0xbeccc)
#12 0x0000aaaacc48d580 testing::TestInfo::Run() (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb/unittests/Host/./HostTests+0xc0580)
#13 0x0000aaaacc48dca8 testing::TestSuite::Run() (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb/unittests/Host/./HostTests+0xc0ca8)
#14 0x0000aaaacc49b55c testing::internal::UnitTestImpl::RunAllTests() (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb/unittests/Host/./HostTests+0xce55c)
#15 0x0000aaaacc49adb8 testing::UnitTest::Run() (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb/unittests/Host/./HostTests+0xcddb8)
#16 0x0000aaaacc483540 main (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb/unittests/Host/./HostTests+0xb6540)
#17 0x0000ffffb01e73fc __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#18 0x0000ffffb01e74cc call_init ./csu/../csu/libc-start.c:128:20
#19 0x0000ffffb01e74cc __libc_start_main ./csu/../csu/libc-start.c:379:5
#20 0x0000aaaacc3f4670 _start (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb/unittests/Host/./HostTests+0x27670)
--
exit: -6
--

@leonardchan I think D153091 will fix the abort (-6 should be SIGABRT), therefore it should be the assertion check of re-initialization in FileSystem::Instance.
Is there a way to run the Linux builder with D153091 to make sure it will fix it?

Verified D153091 fixed TerminalTest failures.

from Failed Tests (13)
https://lab.llvm.org/buildbot/#/builders/96/builds/40769

to Failed Tests (1)
https://lab.llvm.org/buildbot/#/builders/96/builds/40781

will submit a diff to fix the last one, MainLoopTest.DetectsEOF

[ RUN      ] MainLoopTest.DetectsEOF
 #0 0x0000aaaae2a5c738 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb/unittests/Host/./HostTests+0xa0738)
 #1 0x0000aaaae2a5ac6c llvm::sys::RunSignalHandlers() (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb/unittests/Host/./HostTests+0x9ec6c)
 #2 0x0000aaaae2a5cfdc SignalHandler(int) Signals.cpp:0:0
 #3 0x0000ffff957c0598 (linux-vdso.so.1+0x598)
 #4 0x0000ffff94fcf200 __pthread_kill_implementation ./nptl/./nptl/pthread_kill.c:44:76
 #5 0x0000ffff94f8a67c gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #6 0x0000ffff94f77130 abort ./stdlib/./stdlib/abort.c:81:7
 #7 0x0000aaaae29e52e4 testing::AssertionResult testing::internal::CmpHelperEQ<lldb_private::URI, lldb_private::URI>(char const*, char const*, lldb_private::URI const&, lldb_private::URI const&) (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb/unittests/Host/./HostTests+0x292e4)
 #8 0x0000aaaae2aaa234 lldb_private::FileSystem::Instance() (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb/unittests/Host/./HostTests+0xee234)
 #9 0x0000aaaae2ab2f7c lldb_private::PseudoTerminal::OpenSecondary(int) (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb/unittests/Host/./HostTests+0xf6f7c)
#10 0x0000aaaae29f5458 MainLoopTest_DetectsEOF_Test::TestBody() (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb/unittests/Host/./HostTests+0x39458)
#11 0x0000aaaae2a7ae80 testing::Test::Run() (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb/unittests/Host/./HostTests+0xbee80)
#12 0x0000aaaae2a7c5e4 testing::TestInfo::Run() (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb/unittests/Host/./HostTests+0xc05e4)
#13 0x0000aaaae2a7cd0c testing::TestSuite::Run() (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb/unittests/Host/./HostTests+0xc0d0c)
#14 0x0000aaaae2a8a5c0 testing::internal::UnitTestImpl::RunAllTests() (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb/unittests/Host/./HostTests+0xce5c0)
#15 0x0000aaaae2a89e1c testing::UnitTest::Run() (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb/unittests/Host/./HostTests+0xcde1c)
#16 0x0000aaaae2a725a4 main (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb/unittests/Host/./HostTests+0xb65a4)
#17 0x0000ffff94f773fc __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#18 0x0000ffff94f774cc call_init ./csu/../csu/libc-start.c:128:20
#19 0x0000ffff94f774cc __libc_start_main ./csu/../csu/libc-start.c:379:5
#20 0x0000aaaae29e3670 _start (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb/unittests/Host/./HostTests+0x27670)

--
exit: -6

D153102 should fix the last test failure.