compiler-rt | Project moved to https | Code Analyzer library
kandi X-RAY | compiler-rt Summary
kandi X-RAY | compiler-rt Summary
Project moved to: https://github.com/llvm/llvm-project
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of compiler-rt
compiler-rt Key Features
compiler-rt Examples and Code Snippets
Community Discussions
Trending Discussions on compiler-rt
QUESTION
Googling around finds several pages showing instructions based on yum for older variants of clang. I'm an experienced programmer but know almost nothing about administration, for instance don't know yum and the commands don't seem to work as shown. I do use dnf, and the following resulted in clang being runnable but apparently either not finding or not knowing to link to the Standard C++ library, math library and so on. The same command with g++ works fine.
...ANSWER
Answered 2020-May-09 at 15:53Clang, the project/toolchain, can indeed compile more than just C programs. It can also handle C++, Objective-C and Objective-C++.
But, you have to tell it to do so.
The project's binary clang
deals with C, and thus will not (by default) link in the C++ standard library.
The project's binary clang++
will do so.
Write clang++
for C++.
QUESTION
I'd like to be able to save argv into a struct so that it can be passed to functions like so:
...ANSWER
Answered 2020-Apr-02 at 03:24You can simply change to:
QUESTION
From What is the purpose of the _chkstk() function?:
At the end of the stack, there is one guard page mapped as inaccessible memory -- if the program accesses it (because it is trying to use more stack than is currently mapped), there's an access violation.
_chkstk()
is a special compiler-helper function which
ensures that there is enough space for the local variables
i.e. it's doing some stack probing (here is an LLVM example).
This case is Windows-specific. So Windows has some solution to the problem.
Let's consider the similar conditions under Linux (or some other Unix-like): we have a lot of function's local variables. The first stack variable access is behind the stack segment (e.g. mov eax, [esp-LARGE_NUMBER]
, here esp-LARGE_NUMBER is something behind the stack segment). Is there any features to prevent possible page fault or whatever in Linux (perhaps other Unix-like) or development tools like gcc, clang, etc? Does -fstack-check
(GCC stack checking) somehow solve this problem? This answer states that it is something very similar to _chkstk()
.
P.S. These posts 1, 2 didn't help a lot.
P.P.S. In general, the question is about implementation differences between OSs (foremost Linux vs Windows) approaches of struggling with huge amount of stack variables, that climb behind the stack segment. Both C++ and C tags are added because it's about Linux native binary producing, but the assembly code is compiler-related.
...ANSWER
Answered 2020-Mar-31 at 04:06_chkstk
does stack probes to make sure each page is touched in order after a (potentially) large allocation, e.g. an alloca. Because Windows will only grow the stack one page at a time up to the stack size limit.
Touching that "guard page" triggers stack growth. It doesn't guard against stack overflow; I think you're misinterpreting the meaning of "guard page" in this usage.
The function name is also potentially misleading. _chkstk
docs simply say: Called by the compiler when you have more than one page of local variables in your function. It doesn't truly check anything, it just makes sure that intervening pages have been touched before memory around esp
/rsp
gets used. i.e. the only possible effects are: nothing (possibly including a valid soft page fault) or an invalid page-fault on stack overflow (trying to touch a page that Windows refused to grow the stack to include.) It ensures that the stack pages are allocated by unconditionally writing them.
I guess you could look at this as checking for a stack clash by making sure you touch an unmappable page before continuing in the case of stack overflow.
Linux will grow the main-thread stack1 by any number of pages (up to the stack size limit set by ulimit -s
; default 8MiB) when you touch memory below old stack pages if it's above the current stack pointer.
If you touch memory outside the growth limit, or don't move the stack pointer first, it will just segfault. Thus Linux doesn't need stack probes, merely to move the stack pointer by as many bytes as you want to reserve. Compilers know this and emit code accordingly.
See also How is Stack memory allocated when using 'push' or 'sub' x86 instructions? for more low-level details on what the Linux kernel does, and what glibc pthreads on Linux does.
A sufficiently large alloca
on Linux can move the stack all the way past the bottom of the stack growth region, beyond the guard pages below that, and into another mapping; this is a Stack Clash. https://blog.qualys.com/securitylabs/2017/06/19/the-stack-clash It of course requires that the program uses a potentially-huge size for alloca, dependent on user input. The mitigation for CVE-2017-1000364 is to leave a 1MiB guard region, requiring a much larger alloca than normal to get past the guard pages.
This 1MiB guard region is below the ulimit -s
(8MiB) growth limit, not below the current stack pointer. It's separate from Linux's normal stack growth mechanism.
gcc -fstack-check
The effect of gcc -fstack-check
is essentially the same as what's always needed on Windows (which MSVC does by calling _chkstk
): touch stack pages in between previous and new stack pointer when moving it by a large or runtime-variable amount.
But the purpose / benefit of these probes is different on Linux; it's never needed for correctness in a bug-free program on GNU/Linux. It "only" defends against stack-clash bugs/exploits.
On x86-64 GNU/Linux, gcc -fstack-check
will (for functions with a VLA or large fixe-size array) add a loop that does stack probes with or qword ptr [rsp], 0
along with sub rsp,4096
. For known fixed array sizes, it can be just a single probe. The code-gen doesn't look very efficient; it's normally never used on this target. (Godbolt compiler explorer example that passes a stack array to a non-inline function.)
https://gcc.gnu.org/onlinedocs/gccint/Stack-Checking.html describes some GCC internal parameters that control what -fstack-check
does.
If you want absolute safety against stack-clash attacks, this should do it. It's not needed for normal operation, though, and a 1MiB guard page is enough for most people.
Note that -fstack-protector-strong
is completely different, and guards against overwrite of the return address by buffer overruns on local arrays. Nothing to do with stack clashes, and the attack is against stuff already on the stack above a small local array, not against other regions of memory by moving the stack a lot.
Footnote 1: Thread stacks on Linux (for threads other than the initial one) have to be fully allocated up front because the magic growth feature doesn't work. Only the initial aka main thread of a process can have that.
(There's an mmap(MAP_GROWSDOWN)
feature but it's not safe because there's no limit, and because nothing stops other dynamic allocations from randomly picking a page close below the current stack, limiting future growth to a tiny size before a stack clash. Also because it only grows if you touch the guard page, so it would need stack probes. For these showstopper reasons, MAP_GROWSDOWN
is not used for thread stacks. The internal mechanism for the main stack relies on different magic in the kernel which does prevent other allocations from stealing space.)
QUESTION
When I run code that calls notify_all_at_thread_exit() from a detached thread, tsan complains about a data race between pthread_cond_broadcast and pthread_cond_destroy. Am I doing something wrong? Or is this a false positive from tsan?
...ANSWER
Answered 2019-Dec-02 at 02:16Yes, I believe there is a possible race condition.
std::notify_all_at_thread_exit
is specified to do the equivalent of lk.unlock(); cv.notify_all()
as the thread exits. If your main thread were to experience a spurious wakeup immediately after m
is unlocked, then it would see that done
is true
and could reach the end of main
and destroy cv
before cv.notify_all()
gets called.
QUESTION
PROBLEM: I currently have a traditional module instrumentation pass that inserts new function calls into a given IR according to some logic (inserted functions are external from a small lib that is later linked to given program). Running experiments, my overhead is from the cost of executing a function call to the library function.
What I am trying to do: I would like to inline these function bodies into the IR of the given program to get rid of this bottleneck. I assume an intrinsic would be a clean way of doing this, since an intrinsic function would be expanded to its function body when being lowered to ASM (please correct me if my understanding is incorrect here, this is my first time working with intrinsics/LTO).
Current Status:
My original library call definition:
...ANSWER
Answered 2019-Nov-02 at 01:50I'm seeing multiple issues here.
Indeed, you're confusing LTO with intrinsics. Intrinsics are special "functions" that are either expanded into special instructions by a backend or lowered to library function calls. This is certainly not something you're going to achieve. You don't need an intrinsic at all, you'd just need to inline the function call in question: either by hands (from your module pass) or via LTO, indeed.
The particular error comes because you're declaring your intrinsic as receiving an integer argument (and this is how the declaration would look like), but:
- asking the declaration of variadic intrinsic with invalid type (I'd assume your
func_type
is a non-integer type) - passing pointer argument
Hope this makes an issue clear.
QUESTION
I want to build the LLVM project monorepo as a subdirectory to a larger CMake project. But the usual paradigm of add_subdirectory(llvm-project/llvm)
doesn't give the desired results. How can I add LLVM to my CMake project so that building the project also builds LLVM?
I have project tree that looks like this (some files and subdirectories omitted for brevity) :
...ANSWER
Answered 2019-Sep-04 at 19:06@Tsyvarev correctly identified that the problem was in fact that llvm-project/llvm/include/llvm/module.modulemap.build didn't exist. This was because I downloaded an archive of the project through Github, which appears to have excluded .build files by default. When cloning or forking the project, the missing files are present.
The problem is reproducible, but I don't know why Github behaves the way it does. That is beyond the scope of the question.
How can I fix this so that my top level project can build all four subprojects?Using add_subdirectory(llvm-project/llvm)
command in the top-level CMakeLists.txt file is sufficient, but you must also specify LLVM's options at generate time, of course.
QUESTION
I am currently facing an issue when building llvm + compiler-rt under windows. I am using the latest vs 2017 community and cmake to generate the solution. Everything goes smoothly.
I then follow the instructions and everything builds. The problem I have is at install time; I get the following error:
...ANSWER
Answered 2017-Oct-10 at 22:57I have been fighting quite a bit with this but for the time being, I have a workaround. The trick was to trigger the INSTALL target from CMake directly without the need to open visual studio, that seems to do the trick.
to build from CMake I simply did:
QUESTION
I was trying to solve a problem on Codeforces, I am trying to count the number of letters i have to remove so that no two neighbours have same alphabet.
...ANSWER
Answered 2018-Dec-21 at 09:22The problem is with this line:
QUESTION
While beginning my work on CS140e today I've completed phase 3 of the project (writing C code to speak directly to GPIO pins on a Raspberry Pi 3 which would simply blink an LED) but on phase 4, once I attempt to compile my solution in Rust, rustc
seems to not be able to find the aarch64-none-elf
target:
ANSWER
Answered 2018-Aug-20 at 17:57Turns out all I needed to do was run rustup default nightly
and use the nightly version of rustc
, as mentioned in the warning and I'm able to get past that error. If anyone want's to explain why this is, that'd be nice.
QUESTION
I want to build a docker container with clang 6 and libc++ as default C++ standard library. I want to include (and use) the LLVM project clang, libcxx, libcxxabi, lld and compiler-rt.
To set libc++ as default I used the CMAKE option CLANG_DEFAULT_CXX_STDLIB=libc++
(and additionally DCLANG_DEFAULT_RTLIB=compiler-rt
to default to compiler-rt). The first stage build does work, but it seems that libc++ is not installed:
ANSWER
Answered 2018-Aug-08 at 04:49You are missing one other LLVM project, libunwind.
LLVM's libunwind provides a lightweight stack unwinding interface and is tightly coupled with libcxx and libcxxabi.
You should check out libunwind into the projects
folder, and it should be automatically picked by LLVM. You may also need to add -DLIBCXXABI_USE_LLVM_UNWINDER=YES
to CMake command line.
Helpful link: Clang 8 documentation - Assembling a Complete Toolchain.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install compiler-rt
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page