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

Port release_90 patches to LLVM 10 monorepo #1

Merged

Conversation

bryanpkc
Copy link
Collaborator

@bryanpkc bryanpkc commented Aug 18, 2020

This pull request cherry-picks all relevant patches from the release_90 branches in https://github.com/flang-compiler/flang-driver and https://github.com/flang-compiler/llvm, adapts them to fit the monorepo layout, and adjusts the Classic Flang code to let it coexist with the new Flang. To build the code, run CMake with -DLLVM_ENABLE_CLASSIC_FLANG=on.

See https://github.com/Huawei-PTLab/classic-flang-llvm/wiki for an example build script.

schweitzpgi and others added 2 commits August 12, 2020 11:00
Cherry-picked eddca9f374bd7b4b4038909b609771cb2203f927.
Cherry-picked 9d840227b8e054f05ccc0dea90c28a68c47ea8c7:

We don't want to include calls to pthread_[sg]etname_np() as they are
glibc 2.12 functions and SLES uses glibc 2.11 by default.
@kiranchandramohan
Copy link
Collaborator

@bryanpkc Is the CI (results above) running from your repository? Is it expected to fail?

@bryanpkc
Copy link
Collaborator Author

@kiranchandramohan I think those CI jobs came from the GitHub Actions that are configured for your repository:

https://github.com/flang-compiler/classic-flang-llvm-project/actions

These CI jobs are probably incorrect or irrelevant. For our purpose, a useful CI job should build llvm-project with -DLLVM_ENABLE_CLASSIC_FLANG=ON.

@bryanpkc
Copy link
Collaborator Author

I found a bug in my branch; I will push a fix shortly.

@RichBarton-Arm
Copy link
Collaborator

RichBarton-Arm commented Aug 24, 2020 via email

@bryanpkc
Copy link
Collaborator Author

Classic flang had no pre-commit CI on any repositories before so these were not pre-existing CI configs. Presumably you made a fork of llvm/llvm-project to make flang-compiler/classic-flang-llvm-project? Is it possible that these were somehow inherited from llvm/llvm-project when the fork was made?

The master branch in classic-flang-llvm-project does not contain a .github/workflows/ directory, however, the release_100 branch does. The directory is inherited from the release/10.x branch of llvm/llvm-project; I did not add the directory or configure any GitHub Action through the web UI.

It's not a bad idea to have some CI jobs to ensure that this repo is functionally correct, and especially can still build Clang normally.

@bryanpkc
Copy link
Collaborator Author

I have fixed this pull request to allow normal Clang builds and regression tests to succeed, except for the two tests mentioned in issue #2. Ideally we should fix those tests too so that we have a clean branch.

This port adds a USE_CLASSIC_FLANG macro to Clang (a28a4fa), in order to resolve some conflicts between the classic Flang modifications and the F18-related changes in release/10.x. Please let me know if that is acceptable. Most other commits are straightforward cherry-pick of the corresponding patches from flang-compiler/flang-driver and flang-compiler/llvm.

@kiranchandramohan
Copy link
Collaborator

kiranchandramohan commented Sep 2, 2020

Was able to build flang with this monorepo using the build instructions provided. Copying the build instructions below (has trivial modifications to work with this monorepo). All tests in flang passes on Aarch64, two tests in llvm debug fails as @bryanpkc mentions.

I will go through the code next.

#!/bin/bash

buildtype=Release
installdir=$PWD/install

if [ ! -d classic-flang-llvm-project ]; then
  git clone https://github.com/flang-compiler/classic-flang-llvm-project.git
  pushd classic-flang-llvm-project
  git fetch origin pull/1/head:mono10
  git checkout mono10
  popd
fi
if [ ! -d flang ]; then
  git clone https://github.com/flang-compiler/flang
fi

mkdir -p build/llvm
pushd build/llvm
cmake -G Ninja \
  -DCMAKE_BUILD_TYPE=$buildtype \
  -DCMAKE_INSTALL_PREFIX=$installdir \
  -DCMAKE_C_COMPILER=gcc \
  -DCMAKE_CXX_COMPILER=g++ \
  -DLLVM_ENABLE_PROJECTS="clang;openmp" \
  -DLLVM_ENABLE_CLASSIC_FLANG=on \
  -DLLVM_ENABLE_ASSERTIONS=on \
  -DLLVM_OPTIMIZED_TABLEGEN=on \
  -DLLVM_TARGETS_TO_BUILD="X86;AArch64" \
  ../../classic-flang-llvm-project/llvm || exit 1
nice -n 10 ninja install || exit 1
popd

if ! llvm_lit="$(realpath --canonicalize-existing $PWD/build/llvm/bin/llvm-lit 2>/dev/null)" || \
    [ ! -x "$llvm_lit" ]; then
  echo "no usable llvm-lit"
  exit 1
fi

mkdir -p build/libpgmath
pushd build/libpgmath
cmake -G Ninja \
  -DCMAKE_BUILD_TYPE=$buildtype \
  -DCMAKE_INSTALL_PREFIX=$installdir \
  -DCMAKE_C_COMPILER=gcc \
  -DCMAKE_CXX_COMPILER=g++ \
  -DLLVM_CONFIG=$installdir/bin/llvm-config \
  -DLLVM_TARGETS_TO_BUILD="X86;AArch64" \
  -DLIBPGMATH_LLVM_LIT_EXECUTABLE="$llvm_lit" \
  ../../flang/runtime/libpgmath || exit 1
nice -n 10 ninja check-libpgmath install || exit 1
popd

mkdir -p build/flang
pushd build/flang
cmake -Wno-dev -G 'Unix Makefiles' \
  -DCMAKE_BUILD_TYPE=$buildtype \
  -DCMAKE_INSTALL_PREFIX=$installdir \
  -DCMAKE_C_COMPILER=$installdir/bin/clang \
  -DCMAKE_CXX_COMPILER=$installdir/bin/clang++ \
  -DCMAKE_Fortran_COMPILER=$installdir/bin/flang \
  -DLLVM_CONFIG=$installdir/bin/llvm-config \
  -DLLVM_TARGETS_TO_BUILD="X86;AArch64" \
  -DLLVM_EXTERNAL_LIT="$llvm_lit" \
  -DFLANG_LLVM_EXTENSIONS=ON \
  ../../flang || exit 1
nice -n 10 make -j48 install || exit 1
nice -n 10 make check-all || exit 1
popd

echo "SUCCESS"

Copy link
Collaborator

@kiranchandramohan kiranchandramohan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two quick questions.

clang/test/Driver/autocomplete.c Show resolved Hide resolved
clang/lib/Frontend/InitPreprocessor.cpp Show resolved Hide resolved
@kiranchandramohan
Copy link
Collaborator

I have fixed this pull request to allow normal Clang builds and regression tests to succeed, except for the two tests mentioned in issue #2. Ideally we should fix those tests too so that we have a clean branch.

I notice that the build instructions you have do not use the FLANG_LLVM_EXTENSIONS flag while building flang. If you use this flag then there will be DIGlobalVariables without the name field. This happens because there is some code (see link below) in lldebug.cpp which removes names of artificial variables.
https://github.com/flang-compiler/flang/blob/d99e82b764a6622e31bec31e61a80072f5c64291/tools/flang2/flang2exe/lldebug.cpp#L529

The simplest testcase to reproduce the issue is,

module IEEE_ARITHMETIC
  use, intrinsic :: iso_c_binding
end module

@bryanpkc
Copy link
Collaborator Author

bryanpkc commented Sep 5, 2020

I notice that the build instructions you have do not use the FLANG_LLVM_EXTENSIONS flag while building flang. If you use this flag then there will be DIGlobalVariables without the name field. This happens because there is some code (see link below) in lldebug.cpp which removes names of artificial variables.

I based my build instructions on the official build instructions which also did not mention FLANG_LLVM_EXTENSIONS. Let me try to look at the DIGlobalVariable problem a bit further.

@bryanpkc
Copy link
Collaborator Author

bryanpkc commented Sep 7, 2020

@kiranchandramohan I believe it is best to combine FLANG_LLVM_EXTENSIONS and USE_CLASSIC_FLANG into one macro, e.g. CLASSIC_FLANG_LLVM_EXTENSIONS, and use this to switch between the two definitions of DIGlobalVariable, along with other Flang-specific features such as the frontend changes and PGMATH. We could then exclude the two failing unit tests when testing Classic Flang. I can update the branch if you agree that this is the right approach.

Copy link
Contributor

@peterwaller-arm peterwaller-arm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As someone who has been involved in monorepo and driver work elsewhere, this looks broadly good to me. I've reviewed this by studying the diff-of-the-diff vs the release_90 branches on flang-compiler/flang-driver and flang-compiler/llvm.

I think it's possible to simplify the driver, removing the FlangFrontend and instead using the Compiler phase. I've published my preliminary patch, which I will submit for review after this PR has landed, or you're welcome to incorporate those changes here if you feel that is appropriate. I don't mind rebasing as needed for any changes you want to make or include in this patch.

I've highlighted some small issues. I don't think fixing them all needs to hold this PR back.

  • I'd like to see the warning fixed, please.
  • I think merging the two #defines into one is a good idea and have a personal preference for USE_CLASSIC_FLANG, but I'm sure other names would be fine too.

llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Outdated Show resolved Hide resolved
clang/lib/Driver/ToolChains/Clang.cpp Outdated Show resolved Hide resolved
clang/lib/Driver/ToolChains/Clang.cpp Outdated Show resolved Hide resolved
clang/lib/Driver/ToolChains/Clang.cpp Outdated Show resolved Hide resolved
clang/lib/Driver/ToolChains/Clang.cpp Outdated Show resolved Hide resolved
clang/CMakeLists.txt Outdated Show resolved Hide resolved
clang/include/clang/Basic/MacroBuilder.h Show resolved Hide resolved
clang/lib/Driver/ToolChain.cpp Show resolved Hide resolved
clang/lib/Driver/ToolChains/Flang1.cpp Outdated Show resolved Hide resolved
clang/lib/Driver/ToolChains/Flang1.h Outdated Show resolved Hide resolved
@bryanpkc bryanpkc force-pushed the release_100 branch 2 times, most recently from ab8a623 to 9269268 Compare September 10, 2020 12:13
bryanpkc and others added 5 commits September 10, 2020 08:59
Cherry-picked commit 2085211cfcca70411dc63f0d08763facc8a02090 by Eric Schweitz,
resolved merge conflicts, fixed build failures (e.g. adapted CGDebugInfo.cpp to
the new API), and fixed the DIGlobalVariable unit tests, which have been broken
since commit edfad65eebdf045b050f37380b6b61d673513982.
Cherry-picked cabccf8f2d00daf1d740b18a1c80e9b5f4593f60.
Cherry-picked c51f89679135f84675f492d560ec5535c2000cfe by Varun Jayathirtha,
and resolved merge conflicts.

To avoid conflicts with the new Flang, lib/Driver/ToolChains/Flang.{cpp,h}
have been renamed to ClassicFlang.{cpp,h}, and the ENABLE_CLASSIC_FLANG macro
is introduced to select which incarnation of Flang to build. The macro is set
by running CMake with -DLLVM_ENABLE_CLASSIC_FLANG.
Add a new lit feature tag "classic_flang" to select which tests can or cannot be
run when the driver is built for classic Flang. Handle LLVM_ENABLE_CLASSIC_FLANG
in llvm/cmake/modules/HandleLLVMOptions.cmake instead of clang/CMakeLists.txt so
that macro works in both clang and llvm.
Copy link
Contributor

@peterwaller-arm peterwaller-arm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thanks!

Copy link
Collaborator

@kiranchandramohan kiranchandramohan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.
Builds and passes make check-all (llvm and flang) with a Release build on a AArch64 machine.

@kiranchandramohan
Copy link
Collaborator

This now needs approval from @gklimowicz and @shivaramaarao.

@gklimowicz
Copy link
Contributor

I'm working on this today. It may not be done until Wednesday.

Copy link
Collaborator

@shivaramaarao shivaramaarao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. build passed and also the tests passed.

Copy link
Contributor

@gklimowicz gklimowicz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes for classic-flang-llvm-project look fine to me. I have run across 2 failures in check-clang on OpenPOWER, though. The first is in f90_correct/fc30. The second is in f90_correct/ls07.

These failures do not occur on LLVM 10 x86_64 or aarch64.

After digging into these failures, they appear to be related to how LLVM 10 on Power is handling negative zeros during the computation of COMPLEX multiplies. The two tests fail when they generate -0.0 for the imaginary part of a COMPLEX number, when the test results are expecting 0.0.

These need to be investigated further. There's a slight chance these are related to the driver changes in the pull request. It seems more likely to be on the LLVM 10 code-gen side.

I see no reason at this time to hold up approval of this pull request, though.

@bryanpkc
Copy link
Collaborator Author

I have pushed flang-compiler/flang#927 to exclude the test failures in f90_correct and created an issue flang-compiler/flang#928 to track their fix.

@bryanpkc
Copy link
Collaborator Author

@kiranchandramohan I don't have merge privilege in this repository. Could you merge this PR, or give me the access please? I think the PR is good to go now that we have a workaround (even if it hasn't been merged) for the test failures.

@gklimowicz
Copy link
Contributor

@bryanpkc I am adding you to the organization, and then will make sure that you have merge privileges.

@kiranchandramohan
Copy link
Collaborator

kiranchandramohan commented Sep 25, 2020

@bryanpkc I hope @gklimowicz has given you commit access and u can merge now. If not then please let me know.

@bryanpkc
Copy link
Collaborator Author

@kiranchandramohan @gklimowicz has added me to the organization but I don't have merge privilege for this repository yet.

@kiranchandramohan
Copy link
Collaborator

OK @bryanpkc, i can merge. Is merge (no rebase or squash) the best action here?

@bryanpkc
Copy link
Collaborator Author

Please rebase if necessary, but do not squash. Keeping the historical commits separate make them easier to rebase to future release branches. Thank you.

@kiranchandramohan kiranchandramohan merged commit 815dbcc into flang-compiler:release_100 Sep 26, 2020
@kiranchandramohan
Copy link
Collaborator

Flang works on llvm-10 now. Thanks @bryanpkc for your help.

@bryanpkc
Copy link
Collaborator Author

Thanks very much @kiranchandramohan.

@bryanpkc
Copy link
Collaborator Author

bryanpkc commented Oct 6, 2020

@peterwaller-arm Could you submit a pull request for your patch (peterwaller-arm/classic-flang-llvm-project@9078d6c4c8b7)?

@banach-space
Copy link
Contributor

@bryanpkc As discussed in the Flang call yesterday (7/10/20), feel free to cherry-pick that patch and submit it on behalf of Peter. We discussed this with @peterwaller-arm offline and decided that that would be the preferred way.

Peter is currently on a different project and I'm actively working on the driver for the LLVM Flang. If you need reviewers, I volunteer :)

@peterwaller-arm
Copy link
Contributor

I've published a rebase on https://github.com/peterwaller-arm/classic-flang-llvm-project/tree/simplify-driver, that's peterwaller-arm@10dacac. It would be great if someone can pick it up and run with it.

It has an issue: currently the classic_flang.f95 test fails, because the driver thinks that flang is capable of emitting assembly. I think what's going on is that ToolSelector::getTool is combining flang+llvm here: https://github.com/peterwaller-arm/classic-flang-llvm-project/blob/10dacac072ded415449e7350c7ba67c2b500f576/clang/lib/Driver/Driver.cpp#L4110-L4113

As far as I know that is the only issue, but it needs testing with flang and I don't have time to dive in to this for a bit.

michalpasztamobica referenced this pull request in michalpasztamobica/classic-flang-llvm-project Dec 30, 2020
When `Target::GetEntryPointAddress()` calls `exe_module->GetObjectFile()->GetEntryPointAddress()`, and the returned
`entry_addr` is valid, it can immediately be returned.

However, just before that, an `llvm::Error` value has been setup, but in this case it is not consumed before returning, like is done further below in the function.

In https://bugs.freebsd.org/248745 we got a bug report for this, where a very simple test case aborts and dumps core:

```
* thread #1, name = 'testcase', stop reason = breakpoint 1.1
    frame #0: 0x00000000002018d4 testcase`main(argc=1, argv=0x00007fffffffea18) at testcase.c:3:5
   1	int main(int argc, char *argv[])
   2	{
-> 3	    return 0;
   4	}
(lldb) p argc
Program aborted due to an unhandled Error:
Error value was Success. (Note: Success values must still be checked prior to being destroyed).

Thread 1 received signal SIGABRT, Aborted.
thr_kill () at thr_kill.S:3
3	thr_kill.S: No such file or directory.
(gdb) bt
#0  thr_kill () at thr_kill.S:3
#1  0x00000008049a0004 in __raise (s=6) at /usr/src/lib/libc/gen/raise.c:52
#2  0x0000000804916229 in abort () at /usr/src/lib/libc/stdlib/abort.c:67
#3  0x000000000451b5f5 in fatalUncheckedError () at /usr/src/contrib/llvm-project/llvm/lib/Support/Error.cpp:112
#4  0x00000000019cf008 in GetEntryPointAddress () at /usr/src/contrib/llvm-project/llvm/include/llvm/Support/Error.h:267
flang-compiler#5  0x0000000001bccbd8 in ConstructorSetup () at /usr/src/contrib/llvm-project/lldb/source/Target/ThreadPlanCallFunction.cpp:67
flang-compiler#6  0x0000000001bcd2c0 in ThreadPlanCallFunction () at /usr/src/contrib/llvm-project/lldb/source/Target/ThreadPlanCallFunction.cpp:114
flang-compiler#7  0x00000000020076d4 in InferiorCallMmap () at /usr/src/contrib/llvm-project/lldb/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp:97
flang-compiler#8  0x0000000001f4be33 in DoAllocateMemory () at /usr/src/contrib/llvm-project/lldb/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp:604
flang-compiler#9  0x0000000001fe51b9 in AllocatePage () at /usr/src/contrib/llvm-project/lldb/source/Target/Memory.cpp:347
flang-compiler#10 0x0000000001fe5385 in AllocateMemory () at /usr/src/contrib/llvm-project/lldb/source/Target/Memory.cpp:383
flang-compiler#11 0x0000000001974da2 in AllocateMemory () at /usr/src/contrib/llvm-project/lldb/source/Target/Process.cpp:2301
flang-compiler#12 CanJIT () at /usr/src/contrib/llvm-project/lldb/source/Target/Process.cpp:2331
flang-compiler#13 0x0000000001a1bf3d in Evaluate () at /usr/src/contrib/llvm-project/lldb/source/Expression/UserExpression.cpp:190
flang-compiler#14 0x00000000019ce7a2 in EvaluateExpression () at /usr/src/contrib/llvm-project/lldb/source/Target/Target.cpp:2372
flang-compiler#15 0x0000000001ad784c in EvaluateExpression () at /usr/src/contrib/llvm-project/lldb/source/Commands/CommandObjectExpression.cpp:414
flang-compiler#16 0x0000000001ad86ae in DoExecute () at /usr/src/contrib/llvm-project/lldb/source/Commands/CommandObjectExpression.cpp:646
flang-compiler#17 0x0000000001a5e3ed in Execute () at /usr/src/contrib/llvm-project/lldb/source/Interpreter/CommandObject.cpp:1003
flang-compiler#18 0x0000000001a6c4a3 in HandleCommand () at /usr/src/contrib/llvm-project/lldb/source/Interpreter/CommandInterpreter.cpp:1762
flang-compiler#19 0x0000000001a6f98c in IOHandlerInputComplete () at /usr/src/contrib/llvm-project/lldb/source/Interpreter/CommandInterpreter.cpp:2760
flang-compiler#20 0x0000000001a90b08 in Run () at /usr/src/contrib/llvm-project/lldb/source/Core/IOHandler.cpp:548
flang-compiler#21 0x00000000019a6c6a in ExecuteIOHandlers () at /usr/src/contrib/llvm-project/lldb/source/Core/Debugger.cpp:903
flang-compiler#22 0x0000000001a70337 in RunCommandInterpreter () at /usr/src/contrib/llvm-project/lldb/source/Interpreter/CommandInterpreter.cpp:2946
flang-compiler#23 0x0000000001d9d812 in RunCommandInterpreter () at /usr/src/contrib/llvm-project/lldb/source/API/SBDebugger.cpp:1169
flang-compiler#24 0x0000000001918be8 in MainLoop () at /usr/src/contrib/llvm-project/lldb/tools/driver/Driver.cpp:675
flang-compiler#25 0x000000000191a114 in main () at /usr/src/contrib/llvm-project/lldb/tools/driver/Driver.cpp:890```

Fix the incorrect error catch by only instantiating an `Error` object if it is necessary.

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D86355

(cherry picked from commit 1ce07cd)
bryanpkc pushed a commit that referenced this pull request Apr 20, 2022
This patch re-introduces the fix in the commit llvm/llvm-project@66b0cebf7f736 by @yrnkrn

> In DwarfEHPrepare, after all passes are run, RewindFunction may be a dangling
>
> pointer to a dead function. To make sure it's valid, doFinalization nullptrs
> RewindFunction just like the constructor and so it will be found on next run.
>
> llvm-svn: 217737

It seems that the fix was not migrated to `DwarfEHPrepareLegacyPass`.

This patch also updates `llvm/test/CodeGen/X86/dwarf-eh-prepare.ll` to include `-run-twice` to exercise the cleanup. Without this patch `llvm-lit -v llvm/test/CodeGen/X86/dwarf-eh-prepare.ll` fails with

```
-- Testing: 1 tests, 1 workers --
FAIL: LLVM :: CodeGen/X86/dwarf-eh-prepare.ll (1 of 1)
******************** TEST 'LLVM :: CodeGen/X86/dwarf-eh-prepare.ll' FAILED ********************
Script:
--
: 'RUN: at line 1';   /home/arakaki/build/llvm-project/main/bin/opt -mtriple=x86_64-linux-gnu -dwarfehprepare -simplifycfg-require-and-preserve-domtree=1 -run-twice < /home/arakaki/repos/watch/llvm-project/llvm/test/CodeGen/X86/dwarf-eh-prepare.ll -S | /home/arakaki/build/llvm-project/main/bin/FileCheck /home/arakaki/repos/watch/llvm-project/llvm/test/CodeGen/X86/dwarf-eh-prepare.ll
--
Exit Code: 2

Command Output (stderr):
--
Referencing function in another module!
  call void @_Unwind_Resume(i8* %ehptr) #1
; ModuleID = '<stdin>'
void (i8*)* @_Unwind_Resume
; ModuleID = '<stdin>'
in function simple_cleanup_catch
LLVM ERROR: Broken function found, compilation aborted!
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /home/arakaki/build/llvm-project/main/bin/opt -mtriple=x86_64-linux-gnu -dwarfehprepare -simplifycfg-require-and-preserve-domtree=1 -run-twice -S
1.      Running pass 'Function Pass Manager' on module '<stdin>'.
2.      Running pass 'Module Verifier' on function '@simple_cleanup_catch'
 #0 0x000056121b570a2c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/arakaki/repos/watch/llvm-project/llvm/lib/Support/Unix/Signals.inc:569:0
 #1 0x000056121b56eb64 llvm::sys::RunSignalHandlers() /home/arakaki/repos/watch/llvm-project/llvm/lib/Support/Signals.cpp:97:0
 #2 0x000056121b56f28e SignalHandler(int) /home/arakaki/repos/watch/llvm-project/llvm/lib/Support/Unix/Signals.inc:397:0
 #3 0x00007fc7e9b22980 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12980)
 #4 0x00007fc7e87d3fb7 raise /build/glibc-S7xCS9/glibc-2.27/signal/../sysdeps/unix/sysv/linux/raise.c:51:0
 #5 0x00007fc7e87d5921 abort /build/glibc-S7xCS9/glibc-2.27/stdlib/abort.c:81:0
 #6 0x000056121b4e1386 llvm::raw_svector_ostream::raw_svector_ostream(llvm::SmallVectorImpl<char>&) /home/arakaki/repos/watch/llvm-project/llvm/include/llvm/Support/raw_ostream.h:674:0
 #7 0x000056121b4e1386 llvm::report_fatal_error(llvm::Twine const&, bool) /home/arakaki/repos/watch/llvm-project/llvm/lib/Support/ErrorHandling.cpp:114:0
 #8 0x000056121b4e1528 (/home/arakaki/build/llvm-project/main/bin/opt+0x29e3528)
 #9 0x000056121adfd03f llvm::raw_ostream::operator<<(llvm::StringRef) /home/arakaki/repos/watch/llvm-project/llvm/include/llvm/Support/raw_ostream.h:218:0
FileCheck error: '<stdin>' is empty.
FileCheck command line:  /home/arakaki/build/llvm-project/main/bin/FileCheck /home/arakaki/repos/watch/llvm-project/llvm/test/CodeGen/X86/dwarf-eh-prepare.ll

--

********************
********************
Failed Tests (1):
  LLVM :: CodeGen/X86/dwarf-eh-prepare.ll

Testing Time: 0.22s
  Failed: 1
```

Reviewed By: loladiro

Differential Revision: https://reviews.llvm.org/D110979

(cherry picked from commit e8806d7)
bryanpkc pushed a commit to Huawei-CPLLab/classic-flang-llvm-project that referenced this pull request May 5, 2022
In the latest Linux kernels synchronous tag faults
include the tag bits in their address.
This change adds logical and allocation tags to the
description of synchronous tag faults.
(asynchronous faults have no address)

Process 1626 stopped
* thread flang-compiler#1, name = 'a.out', stop reason = signal SIGSEGV: sync tag check fault (fault address: 0x900fffff7ff9010 logical tag: 0x9 allocation tag: 0x0)

This extends the existing description and will
show as much as it can on the rare occasion something
fails.

This change supports AArch64 MTE only but other
architectures could be added by extending the
switch at the start of AnnotateSyncTagCheckFault.
The rest of the function is generic code.

Tests have been added for synchronous and asynchronous
MTE faults.

Reviewed By: omjavaid

Differential Revision: https://reviews.llvm.org/D105178

(cherry picked from commit d510b5f)
kaadam pushed a commit to kaadam/classic-flang-llvm-project that referenced this pull request Jan 4, 2023
We experienced some deadlocks when we used multiple threads for logging
using `scan-builds` intercept-build tool when we used multiple threads by
e.g. logging `make -j16`

```
(gdb) bt
#0  0x00007f2bb3aff110 in __lll_lock_wait () from /lib/x86_64-linux-gnu/libpthread.so.0
flang-compiler#1  0x00007f2bb3af70a3 in pthread_mutex_lock () from /lib/x86_64-linux-gnu/libpthread.so.0
flang-compiler#2  0x00007f2bb3d152e4 in ?? ()
flang-compiler#3  0x00007ffcc5f0cc80 in ?? ()
flang-compiler#4  0x00007f2bb3d2bf5b in ?? () from /lib64/ld-linux-x86-64.so.2
flang-compiler#5  0x00007f2bb3b5da27 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
flang-compiler#6  0x00007f2bb3b5dbe0 in exit () from /lib/x86_64-linux-gnu/libc.so.6
flang-compiler#7  0x00007f2bb3d144ee in ?? ()
flang-compiler#8  0x746e692f706d742f in ?? ()
flang-compiler#9  0x692d747065637265 in ?? ()
flang-compiler#10 0x2f653631326b3034 in ?? ()
flang-compiler#11 0x646d632e35353532 in ?? ()
flang-compiler#12 0x0000000000000000 in ?? ()
```

I think the gcc's exit call caused the injected `libear.so` to be unloaded
by the `ld`, which in turn called the `void on_unload() __attribute__((destructor))`.
That tried to acquire an already locked mutex which was left locked in the
`bear_report_call()` call, that probably encountered some error and
returned early when it forgot to unlock the mutex.

All of these are speculation since from the backtrace I could not verify
if frames 2 and 3 are in fact corresponding to the `libear.so` module.
But I think it's a fairly safe bet.

So, hereby I'm releasing the held mutex on *all paths*, even if some failure
happens.

PS: I would use lock_guards, but it's C.

Reviewed-by: NoQ

Differential Revision: https://reviews.llvm.org/D118439

(cherry picked from commit d919d02)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants