Commit Graph

41 Commits

Author SHA1 Message Date
Evgeniy Stepanov 17d6086a13 Fix CFI tests in sanitizer-ld.
This test is not testing what it is supposed to test because of a
mixup with the CHECK lines.

llvm-svn: 255827
2015-12-16 22:03:39 +00:00
Sumanth Gundapaneni ce7fc17970 [PS4] Fix the unit test to be compatible with clang driver. NFC
".exe" extension is inherently checked by llvm::fs::can_execute()
This patch fixes the linker extension in clang driver and updates the
unit test to accommodate the the check string on windows.

Differential Revision:http://reviews.llvm.org/D15577

llvm-svn: 255814
2015-12-16 20:18:12 +00:00
Evgeniy Stepanov e3fb51cf5a [cfi] Exclude ubsan runtime library from non-diag CFI builds (driver changes).
Split the CFI runtime in two: cfi and cfi_diag. The latter includes
UBSan runtime to allow printing diagnostics.

llvm-svn: 255736
2015-12-16 00:38:42 +00:00
Evgeniy Stepanov fd6f92d5cb Cross-DSO control flow integrity (Clang part).
Clang-side cross-DSO CFI.

* Adds a command line flag -f[no-]sanitize-cfi-cross-dso.
* Links a runtime library when enabled.
* Emits __cfi_slowpath calls is bitset test fails.
* Emits extra hash-based bitsets for external CFI checks.
* Sets a module flag to enable __cfi_check generation during LTO.

This mode does not yet support diagnostics.

llvm-svn: 255694
2015-12-15 23:00:20 +00:00
Filipe Cabecinhas 4585ed006a [PS4] Add missing tests for -fsanitize=...
llvm-svn: 250516
2015-10-16 15:08:01 +00:00
Evgeniy Stepanov 82c00bee3c [safestack] Driver link test for safestack on android.
Safestack runtime should never be linked on Android targets because
it is implemented directly in libc. This is already the case, but
mostly by chance (collectSanitizerRuntimes would only link shared
sanitizer runtimes, and safestack has only a static one). Protect
this behavior with a test.

llvm-svn: 250128
2015-10-12 23:50:19 +00:00
Evgeniy Stepanov 2e6062cd41 Revert r245344.
That change is causing strange test failures on Fedora 22 (PR24503),
and it does not have any effect with Gold linker anyway (PR15823,
https://sourceware.org/bugzilla/show_bug.cgi?id=18859).

llvm-svn: 245619
2015-08-20 21:47:16 +00:00
Evgeniy Stepanov 775d905644 [sanitizer] Add -lutil to static runtime link flags.
This is needed to prevent breakage of -Wl,-as-needed link when
interceptors for functions in libutil are added. See PR15823.

llvm-svn: 245344
2015-08-18 20:36:11 +00:00
Alexey Samsonov d60832eade Allow UBSan+MSan and UBSan+TSan combinations (Clang part).
Embed UBSan runtime into TSan and MSan runtimes in the same as we do
in ASan. Extend UBSan test suite to also run tests for these
combinations.

llvm-svn: 235953
2015-04-28 00:56:36 +00:00
Alexey Samsonov 381845d54f Introduce tsan_cxx and msan_cxx libraries (Clang part).
For now tsan_cxx and msan_cxx contain only operator new/delete
replacements. In the future, when we add support for running UBSan+TSan
and UBSan+MSan, they will also contain bits ubsan_cxx runtime.

llvm-svn: 235924
2015-04-27 22:07:50 +00:00
Nick Lewycky b9489a696e Fix typo in test. There is no %clangcxx, but there is %clangxx.
llvm-svn: 234574
2015-04-10 07:43:19 +00:00
Reid Kleckner 93d0511e8c Use Linux sysroot in Driver test case from r234521
We don't actually need a real Mac sysroot to make the test pass, just a
linker.  This makes the test pass in environments where no ld is on
PATH.

llvm-svn: 234533
2015-04-09 20:37:38 +00:00
Hans Wennborg 10821e5283 [ASan] Don't link against libc++abi when not using libc++
This is a follow-up to r233860 which added -lc++abi when using ASan
on Mac, and broke Chromium's ASan build which doesn't use libc++.

llvm-svn: 234521
2015-04-09 18:47:01 +00:00
Alexey Samsonov 31095469aa [UBSan] Embed UBSan into ASan runtime (Clang part).
Summary:
Change the way we use ASan and UBSan together. Instead of keeping two
separate runtimes (libclang_rt.asan and libclang_rt.ubsan), embed UBSan
into ASan and get rid of libclang_rt.ubsan. If UBSan is not supported on
a platform, all UBSan sources are just compiled into dummy empty object
files. UBSan initialization code (e.g. flag parsing) is directly called
from ASan initialization, so we are able to enforce correct
initialization order.

This mirrors the approach we already use for ASan+LSan. This change doesn't
modify the way we use standalone UBSan.

Test Plan: regression test suite

Reviewers: kubabrecka, zaks.anna, kcc, rsmith

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D8645

llvm-svn: 233860
2015-04-01 22:42:25 +00:00
Alexey Samsonov 3ae177cdb3 [UBSan] Introduce "ubsan_standalone" library (Clang part).
Get rid of "libclang_rt.san" library that used to contain
sanitizer_common pieces required by UBSan if it's used in a standalone
mode. Instead, build two variants of UBSan runtime: "ubsan" and
"ubsan_standalone" (same for "ubsan_cxx" and "ubsan_standalone_cxx").

Later "ubsan" and "ubsan_cxx" libraries will go away, as they will
embedded it into corresponding ASan runtimes.

llvm-svn: 233010
2015-03-23 20:05:42 +00:00
Alexey Samsonov ecf380ef3b [UBSan] Don't allow to use UBSan with anything except for ASan.
We are not able to make a reliable solution for using UBSan together
with other sanitizers with runtime support (and sanitizer_common).
Instead, we want to follow the path used for LSan: have a "standalone"
UBSan tool, and plug-in UBSan that would be explicitly embedded into
specific sanitizers (in short term, it will be only ASan).

llvm-svn: 232829
2015-03-20 18:45:06 +00:00
Alexey Samsonov ecfd5c84ca Revert r218541 - Don't link in sanitizer runtimes if -nostdlib/-nodefaultlibs is provided.
This is a sad thing to do, but all the alternatives look ugly.

Looks like there are legitimate cases when users may want to link
with sanitizer runtimes *and* -nodefaultlibs (and ensure they provide
replacements for system libraries). For example, this happens in libc++
test suite.

"-nodefaultlibs" is told to link only the libraries explicitly provided
by the user, and providing "-fsanitize=address" is a clear indication of
intention to link with ASan runtime.
We can't easily introduce analogue of "-print-libgcc-name": linking with
sanitizers runtimes is not trivial: some runtimes are split into several
archive libraries, which are required to be wrapped in
-whole-archive/-no-whole-archive.

If "-fsanitize=whatever" and "-nodefaultlibs" are provided, system library
dependencies of sanitizer runtimes (-lc/-ldl/-lpthread/-lrt) will *not* be
linked, and user would have to link them in manually. Note that this can
cause problems, as failing to provide "-lrt" might lead to crashes in runtime
during ASan initialization. But looks like we should bite this bullet.

See r218541 review thread for the discussion.

llvm-svn: 220455
2014-10-23 00:46:10 +00:00
Alexey Samsonov 58ae9ae23a Don't link in sanitizer runtimes if -nostdlib/-nodefaultlibs is provided.
It makes no sense to link in sanitizer runtimes in this case: the user
probably doesn't want to see any system/toolchain libs in his link if he
provides these flags, and the link will most likely fail anyway - as sanitizer
runtimes depend on libpthread, libdl, libc etc.

Also, see discussion in https://code.google.com/p/address-sanitizer/issues/detail?id=344

llvm-svn: 218541
2014-09-26 21:22:08 +00:00
Alexey Samsonov 5255034982 Major rewrite of linking strategy for sanitizer runtimes on Linux.
Change 1: we used to add static sanitizer runtimes at the
very beginning of the linker invocation, even before crtbegin.o, which
is gross and not correct in general. Fix this: now addSanitizerRuntimes()
adds all sanitizer-related link flags to the end of the linker invocation
being constructed. It means, that we should call this function in the
correct place, namely, before AddLinkerInputs() to make sure sanitizer
versions of library functions will be preferred.

Change 2: Put system libraries sanitizer libraries depend on at the
end of the linker invocation, where all the rest system libraries are
located. Respect --nodefaultlibs and --nostdlib flags. This is another way
to fix PR15823. Original fix landed in r215940 put "-lpthread" and friends
immediately after static ASan runtime, before the user linker inputs.
This caused significant slowdown in dynamic linker for large binaries
linked against thousands of shared objects. Instead, to mark system
libraries as DT_NEEDED we prepend them with "--no-as-needed" flag,
discarding the "-Wl,--as-needed" flag that could be provided by the user.

Otherwise, this change is a code cleanup. Instead of having a special method
for each sanitizer, we introduce a function collectSanitizerRuntimes() that
analyzes -fsanitize= flags and returns the set of static and shared
libraries that needs to be linked.

llvm-svn: 217817
2014-09-15 19:58:40 +00:00
Evgeniy Stepanov 8f4e736080 [asan] Restore asan-rt name on linux back to pre-r216380.
There is no reason to have different library names for shared and static
cases on linux. It also breaks Android where we install the shared asan-rt
library into the system and should keep the old name.

This change reverts most of r216380 limiting it to win32 targets only.

llvm-svn: 216533
2014-08-27 09:46:54 +00:00
Timur Iskhodzhanov 664dff4db7 Follow-up to r216380: update test expectations
llvm-svn: 216381
2014-08-25 12:19:12 +00:00
Alexey Samsonov c4f1fc2af1 Update link strategy for sanitizer runtime libraries on Linux:
1. Always put static sanitizer runtimes to the front of the linker
invocation line. This was already done for all sanitizers except UBSan:
in case user provides static libstdc++ we need to make sure that new/delete
operator definitions are picked from sanitizer runtimes instead of libstdc++.
We have to put UBSan runtime first for similar reasons: it depends on some
libstdc++ parts (e.g. __dynamic_cast function), and has to go first in
link line to ensure these functions will be picked up from libstdc++.

2. Put sanitizer libraries system dependencies (-ldl, -lpthread etc.) right
after sanitizer runtimes. This will ensure these libraries participate in
the link even if user provided -Wl,-as-needed flag. This should fix PR15823.

3. In case we link in several sanitizer runtimes (e.g. "ubsan", "ubsan_cxx"
and "san"), add system dependencies (-ldl, -lpthread, ...) only once.

llvm-svn: 215940
2014-08-18 22:10:42 +00:00
Alexey Samsonov 90490af21d Add -link-cxx-sanitizer driver flag.
Summary:
This flag can be used to force linking of CXX-specific parts
of sanitizer runtimes into the final executable. It gives more precise
control than --driver-mode=g++ and comes handy when user links several
object files with sanitized C++ code into an executable, but wants
to provide libstdc++ himself, instead of relying on Clang dirver's
behavior.

Test Plan: clang regression test suite

Reviewers: chandlerc, rsmith

Reviewed By: rsmith

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D4824

llvm-svn: 215252
2014-08-08 22:47:17 +00:00
Alexey Samsonov c6496816b1 [UBSan] Don't link UBSan runtime into shared libraries.
It used to be a feature of UBSan (it could sanitize a standalone
shared object instead of the whole program), but now it causes
more problems, like PR20165.

llvm-svn: 212064
2014-06-30 20:27:16 +00:00
Evgeniy Stepanov 6f0ae18a59 Fix driver warning about -shared-libasan on Android.
Asan runtime library is always shared on Android, and -shared-libasan is no-op.
Suppress the unused argument warning.

llvm-svn: 210252
2014-06-05 11:14:00 +00:00
Richard Smith 4244ea9ca1 [ubsan] Don't add a --dynamic-list for ubsan symbols when building a shared
library. That results in the linker resolving all references to weak symbols in
the DSO to the definition from within that DSO. Ironically, this rarely causes
observable problems, except that it causes ubsan's own dynamic type check to
spuriously fail (because we fail to properly merge type_info object names).

llvm-svn: 210220
2014-06-04 23:28:46 +00:00
Alexey Samsonov b01f936ffe [ASan] Split static ASan runtime in two parts: asan and asan_cxx.
asan_cxx containts replacements for new/delete operators, and should
only be linked in C++ mode. We plan to start building this part
with exception support to make new more standard-compliant.

See https://code.google.com/p/address-sanitizer/issues/detail?id=295
for more details.

llvm-svn: 208610
2014-05-12 18:39:51 +00:00
Alexey Samsonov bdfa6c2517 Add support for dynamic ASan runtime (on Linux) to Clang driver.
Based on http://llvm-reviews.chandlerc.com/D3043 by Yuri Gribov!

llvm-svn: 205310
2014-04-01 13:31:10 +00:00
NAKAMURA Takumi a65db1e9ee clang/test/Driver/sanitizer-ld.c: Tweak to accept dos path.
llvm-svn: 204138
2014-03-18 10:47:10 +00:00
Viktor Kutuzov aa5b5f7b0d Add support for sanitizers arguments on FreeBSD
llvm-svn: 204129
2014-03-18 09:36:50 +00:00
Alexey Samsonov e65ceb9f16 Respect ToolChain::isPIEDefault() in constructing link job on Linux and FreeBSD.
Partially based on http://llvm-reviews.chandlerc.com/D2644 by Viktor Kutuzov.

llvm-svn: 202150
2014-02-25 13:26:03 +00:00
Renato Golin e2dbedda76 Add tests for ARM RT library name
llvm-svn: 200539
2014-01-31 12:21:55 +00:00
Peter Collingbourne f7ef3fd810 Revert r193022 and r193048. They broke the ubsan test suite.
llvm-svn: 193057
2013-10-20 21:29:13 +00:00
Benjamin Kramer 80b5a9d2d0 Driver: libubsan_cxx depends on libubsan. Preserve the topological ordering, some linkers depend on it.
llvm-svn: 193048
2013-10-20 12:34:18 +00:00
Nick Lewycky 2492169aee When building ubsan, link in ubsan parts first and sanitizer-common second, to
pick up the common bits ubsan actually needs. Also remove whole-archive when we
aren't trying to re-export the symbols.

llvm-svn: 193022
2013-10-19 00:27:23 +00:00
Nick Lewycky bbd6db8032 Link in the ubsan runtime when building shared objects.
llvm-svn: 188325
2013-08-13 22:32:35 +00:00
Sergey Matveev 1814e9eae3 Add -fsanitize=leak to driver options.
If -fsanitize=leak is specified, link the program with the
LeakSanitizer runtime. Ignore this option when -fsanitize=address is specified,
because AddressSanitizer has this functionality built in.

llvm-svn: 182729
2013-05-27 11:17:01 +00:00
Evgeniy Stepanov 758b5071d1 Add -lrt to sanitizer link arguments.
Sanitizer runtime intercepts functions from librt. Not doing this will fail
if the librt dependency is not present at program startup (ex. comes from a
dlopen()ed library).

llvm-svn: 182645
2013-05-24 14:28:03 +00:00
Richard Smith f3e624ca73 If a .syms file is available alongside a sanitizer runtime, pass it to the
linker via --dynamic-list instead of using --export-dynamic. This reduces the
size of the dynamic symbol table, and thus of the binary (in some cases by up
to ~30%).

llvm-svn: 177783
2013-03-23 00:30:08 +00:00
Richard Smith cff3cde28b Split ubsan runtime into three pieces (clang part):
* libclang_rt-san-* is sanitizer_common, and is linked in only if no other
   sanitizer runtime is present.
 * libclang_rt-ubsan-* is the piece of the runtime which doesn't depend on
   a C++ ABI library, and is always linked in.
 * libclang_rt-ubsan_cxx-* is the piece of the runtime which depends on a
   C++ ABI library, and is only linked in when linking a C++ binary.

This change also switches us to using -whole-archive for the ubsan runtime
(which is made possible by the above split), and switches us to only linking
the sanitizer runtime into the main binary and not into DSOs (which is made
possible by using -whole-archive).

The motivation for this is to only link a single copy of sanitizer_common
into any binary. This is becoming important now because we want to share
more state between multiple sanitizers in the same process (for instance,
we want a single shared output mutex).

The Darwin ubsan runtime is unchanged; because we use a DSO there, we don't
need this complexity.

llvm-svn: 177605
2013-03-20 23:49:07 +00:00
Alexey Samsonov bfb0cd355f [Sanitizer] Change driver behavior when linking with -fsanitize=thread and -fsanitize=memory. TSan/MSan also provide their versions of new/delete and should use the same strategy as ASan. Share the code that sets linker flags for all sanitizers.
llvm-svn: 176178
2013-02-27 11:14:55 +00:00