Summary: | projects/clang380-import for TARGET_ARCH=powerpc : clang 3.8.0 sometimes mishandles va_list overflow_arg_area vs. reg_save_area | ||
---|---|---|---|
Product: | Base System | Reporter: | Mark Millard <marklmi26-fbsd> |
Component: | bin | Assignee: | freebsd-bugs (Nobody) <bugs> |
Status: | Closed Overcome By Events | ||
Severity: | Affects Only Me | CC: | jhibbits |
Priority: | --- | ||
Version: | CURRENT | ||
Hardware: | powerpc | ||
OS: | Any |
Description
Mark Millard
2016-02-14 02:42:41 UTC
(In reply to Mark Millard from comment #0) I have submitted this to llvm as 26605 ( https://llvm.org/bugs/show_bug.cgi?id=26605 ). (In reply to Mark Millard from comment #1) The following has been submitted to llvm 26605. It matches up with the exchange on the lists. Roman Divacky (rdivacky at vlakno.cz) came up with the following patch [other than some discussion of what turned into "(8)" in "getIn8(8)" below]. The svnlite diff below is from my testing area for projects/clang380-import in FreeBSD's svn. So the revision number is from there too. Index: /usr/src/contrib/llvm/tools/clang/lib/CodeGen/TargetInfo.cpp =================================================================== --- /usr/src/contrib/llvm/tools/clang/lib/CodeGen/TargetInfo.cpp (revision 295601) +++ /usr/src/contrib/llvm/tools/clang/lib/CodeGen/TargetInfo.cpp (working copy) @@ -3569,6 +3569,8 @@ { CGF.EmitBlock(UsingOverflow); + Builder.CreateStore(Builder.getInt8(8), NumRegsAddr); + // Everything in the overflow area is rounded up to a size of at least 4. CharUnits OverflowAreaAlign = CharUnits::fromQuantity(4); The "(8)" is intended to match the "(8)" from: llvm::Value *CC = Builder.CreateICmpULT(NumRegs, Builder.getInt8(8), "cond"); My simple test cases and FreeBSD's clang380-import "buildworld" materials (built with the udpate clang 3.8.0) all indicate that this fixes the problem reported. For example each of the following now work based on code generation from the patched clang 3.8.0: la -l -n / svnlite update -295601 /usr/src Both are from using the patched clang 3.8.0 to "buildworld" and then install it and reboot and use the software. The FreeBSD vintage started from is projects/clang380-import -r295601 . I did some testing with doubles in use as a variant of my simplified example as well in order to test the fpr related handling, not just gpr related. The mix worked fine. [Note: I run with the signal delivery modified to have a "red zone" to deal with other aspects of clang 3.8.0 code generation that are currently not ABI compliant for when the stack pointer is moved. Having a "red zone" is still operationally correct for an ABI compliant code generation, it just temporarily wastes more bytes. Also: the kernel was built with gcc 4.2.1 but world was built with the patched clang 3.8.0. At this stage I've only been identifying issues with "world" vs. clang 3.8.0. The kernel is a much more involved issue.] https://llvm.org/bugs/show_bug.cgi?id=26605 got its fix in llvm's 261422 check in. But it is going to be some time [weeks or months] before I again have access to the powerpcs that I had been using. I'm not currently set up to check 11.0 -r310975 on powerpc's [or powerpc64's]. I expect that this specific issue is fixed. [But I'll note that there are many other problems for powerpc [and powerpc64] code generation via clang. For powerpc it does not follow the stack handling part of the expected ABI correctly. Testing the fix involves sidestepping the ABI requirement so that clang's generated code is tolerated. With such work arounds I've only gotten as far as buildworld being clang based, not buildkernel.] (In reply to Mark Millard from comment #3) I have tested compiling and running va_test.c under the system compiler for: # uname -apKU FreeBSD FBSDG4S 12.0-CURRENT FreeBSD 12.0-CURRENT #0 r308247M: Thu Nov 3 11:39:11 PDT 2016 markmi@FreeBSDx64:/usr/obj/powerpcvtsc_clang_gcc421_kernel/powerpc.powerpc/usr/src/sys/GENERICvtsc-NODBG powerpc powerpc 1200014 1200014 which is still clang 3.8.0 based (like stable/11 and release/11.0). It does not get the reported SEGV and completes normally. But this is from my environment for working around other clang problems when it targets powerpc. This should've been fixed by newer clang imports. If not, please reopen with newer data. (In reply to Justin Hibbits from comment #5) So far as I know FreeBSD's ABI is being followed now and is working for var args. I've not observed any problems in a long time. Side note: llvm bugzilla 33108 is about darwin's ABI not being handled correctly for some aspects of var args. |