Commit Graph

106 Commits

Author SHA1 Message Date
Nico Weber e5653be62a compiler-rt tests: Unbreak cmake with LLVM_ENABLE_PIC=OFF on mac
The LTO target doesn't exist with LLVM_ENABLE_PIC turned off.

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

llvm-svn: 351373
2019-01-16 20:36:27 +00:00
David Carlier dc0624844f [Cfi] Compiling cfi library on FreeBSD and NetBSD
Making the library slighty more portable.

Reviewers: vitalybuka, krytarowski

Reviewed By: vitalybuka

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

llvm-svn: 343510
2018-10-01 18:01:55 +00:00
Petr Hosek eb46c95c3e [CMake] Use normalized Windows target triples
Changes the default Windows target triple returned by
GetHostTriple.cmake from the old environment names (which we wanted to
move away from) to newer, normalized ones. This also requires updating
all tests to use the new systems names in constraints.

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

llvm-svn: 339307
2018-08-09 02:16:18 +00:00
Peter Collingbourne acf005676e Change the cap on the amount of padding for each vtable to 32-byte (previously it was 128-byte)
We tested different cap values with a recent commit of Chromium. Our results show that the 32-byte cap yields the smallest binary and all the caps yield similar performance.
Based on the results, we propose to change the cap value to 32-byte.

Patch by Zhaomo Yang!

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

llvm-svn: 337622
2018-07-20 21:43:20 +00:00
Teresa Johnson 293b0f43ac [compiler-rt] Add NewPM testing to CFI tests
Summary:
Executes both LTO and ThinLTO CFI tests an additional time using the new
pass manager. I only bothered to add with gold and not lld as testing
with one linker should be sufficient. I didn't add for APPLE or WIN32
since I don't have a way to test those.

Depends on D49429.

Reviewers: pcc

Subscribers: dberris, mgorny, mehdi_amini, delcypher, dexonsmith, #sanitizers, llvm-commits

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

llvm-svn: 337465
2018-07-19 15:32:48 +00:00
Evgeniy Stepanov d77e7ba74e [cfi] Use __builtin version of __clear_cache.
__builtin___clear_cache is also present on X86 and does the right thing (i.e. nop) there.

llvm-svn: 335997
2018-06-29 17:22:58 +00:00
Evgeniy Stepanov 6d310651a2 [cfi] Reset i-cache after copying code in test.
Fixes intermittent crashes on Android.
Also add PROT_READ to the code mapping for no real reason.

llvm-svn: 335943
2018-06-29 00:38:26 +00:00
Haojian Wu d93a1e5271 Correct the test modified in rL335777.
llvm-svn: 335865
2018-06-28 15:24:34 +00:00
Vlad Tsyrklevich 600a2df289 Another shot at fixing android r335644 failure
The android buildbot moves the build outputs to a different directory
and rewrites the executable path, the DSO passed as an argument does not
get re-written. Use rpaths to load the DSO the same way the
test/cfi/cross-dso/ tests do and test the DSO name differently.

llvm-svn: 335777
2018-06-27 20:00:55 +00:00
Vlad Tsyrklevich 5417225745 Fix another bot broken by r335644
The android sanitizer bot can't resolve the function name in the DSO and
it's not relevant to the test.

llvm-svn: 335693
2018-06-27 00:31:17 +00:00
Vlad Tsyrklevich ee59c5e922 Fix test broken by r335644
llvm-svn: 335657
2018-06-26 20:21:33 +00:00
Vlad Tsyrklevich e745cf9bf3 CFI: Print DSO names for failed cross-DSO icalls
Reviewers: pcc

Reviewed By: pcc

Subscribers: kubamracek, delcypher, llvm-commits, kcc, #sanitizers

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

llvm-svn: 335644
2018-06-26 18:51:04 +00:00
Peter Collingbourne f99bc0b2f6 Mark mfcall.cpp as UNSUPPORTED: win32.
llvm-svn: 335573
2018-06-26 02:59:22 +00:00
Peter Collingbourne e44acadf6a Implement CFI for indirect calls via a member function pointer.
Similarly to CFI on virtual and indirect calls, this implementation
tries to use program type information to make the checks as precise
as possible.  The basic way that it works is as follows, where `C`
is the name of the class being defined or the target of a call and
the function type is assumed to be `void()`.

For virtual calls:
- Attach type metadata to the addresses of function pointers in vtables
  (not the functions themselves) of type `void (B::*)()` for each `B`
  that is a recursive dynamic base class of `C`, including `C` itself.
  This type metadata has an annotation that the type is for virtual
  calls (to distinguish it from the non-virtual case).
- At the call site, check that the computed address of the function
  pointer in the vtable has type `void (C::*)()`.

For non-virtual calls:
- Attach type metadata to each non-virtual member function whose address
  can be taken with a member function pointer. The type of a function
  in class `C` of type `void()` is each of the types `void (B::*)()`
  where `B` is a most-base class of `C`. A most-base class of `C`
  is defined as a recursive base class of `C`, including `C` itself,
  that does not have any bases.
- At the call site, check that the function pointer has one of the types
  `void (B::*)()` where `B` is a most-base class of `C`.

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

llvm-svn: 335569
2018-06-26 02:15:47 +00:00
Peter Collingbourne 43b055f8b1 cfi: Disable simple-pass.cpp on Darwin.
-mretpoline does not work yet on Darwin.

llvm-svn: 327168
2018-03-09 20:41:56 +00:00
Peter Collingbourne 2974856ad4 Use branch funnels for virtual calls when retpoline mitigation is enabled.
The retpoline mitigation for variant 2 of CVE-2017-5715 inhibits the
branch predictor, and as a result it can lead to a measurable loss of
performance. We can reduce the performance impact of retpolined virtual
calls by replacing them with a special construct known as a branch
funnel, which is an instruction sequence that implements virtual calls
to a set of known targets using a binary tree of direct branches. This
allows the processor to speculately execute valid implementations of the
virtual function without allowing for speculative execution of of calls
to arbitrary addresses.

This patch extends the whole-program devirtualization pass to replace
certain virtual calls with calls to branch funnels, which are
represented using a new llvm.icall.jumptable intrinsic. It also extends
the LowerTypeTests pass to recognize the new intrinsic, generate code
for the branch funnels (x86_64 only for now) and lay out virtual tables
as required for each branch funnel.

The implementation supports full LTO as well as ThinLTO, and extends the
ThinLTO summary format used for whole-program devirtualization to
support branch funnels.

For more details see RFC:
http://lists.llvm.org/pipermail/llvm-dev/2018-January/120672.html

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

llvm-svn: 327163
2018-03-09 19:11:44 +00:00
Roman Lebedev d45054dbd2 [ubsan] Re-commit: lit changes for lld testing, future lto testing.
Summary:
As discussed in https://github.com/google/oss-fuzz/issues/933,
it would be really awesome to be able to use ThinLTO for fuzzing.
However, as @kcc has pointed out, it is currently undefined (untested)
whether the sanitizers actually function properly with LLD and/or LTO.

This patch is inspired by the cfi test, which already do test with LTO
(and/or LLD), since LTO is required for CFI to function.

I started with UBSan, because it's cmakelists / lit.* files appeared
to be the cleanest. This patch adds the infrastructure to easily add
LLD and/or LTO sub-variants of the existing lit test configurations.

Also, this patch adds the LLD flavor, that explicitly does use LLD to link.
The check-ubsan does pass on my machine. And to minimize the [initial]
potential buildbot breakage i have put some restrictions on this flavour.

Please review carefully, i have not worked with lit/sanitizer tests before.

The original attempt, r319525 was reverted in r319526 due
to the failures in compiler-rt standalone builds.

Reviewers: eugenis, vitalybuka

Reviewed By: eugenis

Subscribers: #sanitizers, pcc, kubamracek, mgorny, llvm-commits, mehdi_amini, inglorion, kcc

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

llvm-svn: 319575
2017-12-01 19:36:29 +00:00
Roman Lebedev 85653e3db9 Revert "[ubsan] lit changes for lld testing, future lto testing."
This reverts commit r319525.

This change has introduced a problem with the Lit tests build for compiler-rt using Gold: http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux/builds/6047/steps/test%20standalone%20compiler-rt/logs/stdio

llvm-lit: /b/sanitizer-x86_64-linux/build/llvm/utils/lit/lit/TestingConfig.py:101: fatal: unable to parse config file '/b/sanitizer-x86_64-linux/build/llvm/projects/compiler-rt/test/profile/Linux/lit.local.cfg', traceback: Traceback (most recent call last):
  File "/b/sanitizer-x86_64-linux/build/llvm/utils/lit/lit/TestingConfig.py", line 88, in load_from_path
    exec(compile(data, path, 'exec'), cfg_globals, None)
  File "/b/sanitizer-x86_64-linux/build/llvm/projects/compiler-rt/test/profile/Linux/lit.local.cfg", line 37, in <module>
    if root.host_os not in ['Linux'] or not is_gold_linker_available():
  File "/b/sanitizer-x86_64-linux/build/llvm/projects/compiler-rt/test/profile/Linux/lit.local.cfg", line 27, in is_gold_linker_available
    stderr = subprocess.PIPE)
  File "/usr/lib/python2.7/subprocess.py", line 390, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1024, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory
llvm-svn: 319529
2017-12-01 10:09:27 +00:00
Roman Lebedev 0d044dc090 [ubsan] lit changes for lld testing, future lto testing.
Summary:
As discussed in https://github.com/google/oss-fuzz/issues/933,
it would be really awesome to be able to use ThinLTO for fuzzing.
However, as @kcc has pointed out, it is currently undefined (untested)
whether the sanitizers actually function properly with LLD and/or LTO.

This patch is inspired by the cfi test, which already do test with LTO
(and/or LLD), since LTO is required for CFI to function.

I started with UBSan, because it's cmakelists / lit.* files appeared
to be the cleanest. This patch adds the infrastructure to easily add
LLD and/or LTO sub-variants of the existing lit test configurations.

Also, this patch adds the LLD flavor, that explicitly does use LLD to link.
The check-ubsan does pass on my machine. And to minimize the [initial]
potential buildbot breakage i have put some restrictions on this flavour.

Please review carefully, i have not worked with lit/sanitizer tests before.

Reviewers: eugenis, vitalybuka

Reviewed By: eugenis

Subscribers: #sanitizers, pcc, kubamracek, mgorny, llvm-commits, mehdi_amini, inglorion, kcc

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

llvm-svn: 319525
2017-12-01 08:38:25 +00:00
Peter Collingbourne dd01ddbe67 Enable PDB generation with lld in asan and cfi tests on Windows.
PDB emission now works well enough that we can rely on it for these
tests to pass.

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

llvm-svn: 318546
2017-11-17 19:49:41 +00:00
Evgeniy Stepanov 1993de54ee [cfi] Test cross-dso CFI on Android.
Reviewers: vitalybuka, pcc

Subscribers: llvm-commits, srhines

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

llvm-svn: 315922
2017-10-16 18:03:11 +00:00
Evgeniy Stepanov f156c932ae [cfi] Use %ld_flags_rpath_* substitutions in tests (NFC)
llvm-svn: 315775
2017-10-13 23:33:12 +00:00
Peter Collingbourne 868783e855 LowerTypeTests: Give imported symbols a type with size 0 so that they are not assumed not to alias.
It is possible for both a base and a derived class to be satisfied
with a unique vtable. If a program contains casts of the same pointer
to both of those types, the CFI checks will be lowered to this
(with ThinLTO):

if (p != &__typeid_base_global_addr)
  trap();
if (p != &__typeid_derived_global_addr)
  trap();

The optimizer may then use the first condition combined
with the assumption that __typeid_base_global_addr and
__typeid_derived_global_addr may not alias to optimize away the second
comparison, resulting in an unconditional trap.

This patch fixes the bug by giving imported globals the type [0 x i8]*,
which prevents the optimizer from assuming that they do not alias.

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

llvm-svn: 315753
2017-10-13 21:02:16 +00:00
Evgeniy Stepanov f29ee9a050 [sanitizer] Test ubsan and cfi on android.
Summary:
Enable check-cfi and check-ubsan on Android.
Check-ubsan includes standalone and ubsan+asan, but not tsan or msan.
Cross-dso cfi tests are disabled for now.

Reviewers: vitalybuka, pcc

Subscribers: srhines, kubamracek, llvm-commits, mgorny

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

llvm-svn: 315105
2017-10-06 20:51:51 +00:00
Evgeniy Stepanov 0d0325606b [cfi] Disable tests with lld on i386.
bin/ld.lld: error: ubsan_handlers.cc:(.debug_info+0x80D5D): has non-ABS reloc

Bug pending.

llvm-svn: 315027
2017-10-05 22:07:21 +00:00
Evgeniy Stepanov 3b87cc910e [sanitizer] Move %ld_flags_rpath_exe to common and use it in more tests.
Reviewers: vitalybuka

Subscribers: kubamracek, llvm-commits

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

llvm-svn: 315010
2017-10-05 20:00:07 +00:00
Evgeniy Stepanov ca6c8e85d1 [cfi] Mark a test as unsupported on darwin.
llvm-svn: 315007
2017-10-05 19:36:15 +00:00
Evgeniy Stepanov f7e14f4c72 [cfi] Test on all available targets.
Summary:
Run CFI tests on all targets current toolchain can target.
On multiarch Linux, this will run all CFI tests with -m32 and -m64.

Reviewers: pcc

Subscribers: mgorny, llvm-commits

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

llvm-svn: 315001
2017-10-05 18:28:04 +00:00
Filipe Cabecinhas 3ccd23e116 Use %run for running CFI tests
Reviewers: pcc, krasin, eugenis

Subscribers: llvm-commits

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

llvm-svn: 314659
2017-10-02 10:21:26 +00:00
Peter Collingbourne d13d61fdb4 ubsan: Unbreak ubsan_cxx runtime library on Windows.
This was originally broken by r258744 which introduced a weak reference
from ubsan to ubsan_cxx. This reference does not work directly on
Windows because COFF has no direct concept of weak symbols. The fix is
to use /alternatename to create a weak external reference to ubsan_cxx.

Also fix the definition (and the name, so that we drop cached values)
of the cmake flag that controls whether to build ubsan_cxx. Now the
user-controllable flag is always on, and we turn it off internally
depending on whether we support building it.

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

llvm-svn: 313391
2017-09-15 20:24:12 +00:00
Peter Collingbourne a02c2eaf52 cfi: Enable ThinLTO tests on Windows.
We now avoid using absolute symbols on Windows (D37407 and D37408),
so this should work.

Fixes PR32770.

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

llvm-svn: 313379
2017-09-15 18:55:35 +00:00
Sean Fertile 6e5e0bcd80 [cfi] only add cfi tests on supported arches.
Differential Revision:  https://reviews.llvm.org/D35101

llvm-svn: 311745
2017-08-25 01:50:53 +00:00
Hiroshi Inoue 85c529c988 fix trivial typo; NFC
llvm-svn: 306955
2017-07-01 08:58:47 +00:00
Evgeniy Stepanov 2aed0fb07e [cfi] Enable icall tests with thinlto.
llvm-svn: 305534
2017-06-16 00:18:35 +00:00
Evgeniy Stepanov 0b11403d55 [cfi] Fix wrong CMake condition for WIN32.
llvm-svn: 301257
2017-04-24 21:27:47 +00:00
Evgeniy Stepanov 5d7633f75d [cfi] Disable ThinLTO + CFI tests on Windows.
PR32770.

llvm-svn: 301235
2017-04-24 19:52:51 +00:00
Ahmed Bougacha ea84c1687c [cfi] Disable thinlto tests on Darwin.
These were added in r301016, but they're failing, because
-fsanitize=cfi seemingly causes -flto=thin to emit raw bitcode objects,
rather than the mach-o-wrapped bitcode we emit with -flto=thin alone.

That causes all tests to fail with ld64 errors.

Filed PR32741.

llvm-svn: 301065
2017-04-22 00:07:47 +00:00
Evgeniy Stepanov f608a0a778 [cfi] Replace elif with elseif in cmake.
Apparently, elif() is deprecated.

llvm-svn: 301022
2017-04-21 19:22:15 +00:00
Evgeniy Stepanov ca32b682f6 [cfi] Run tests with and without lld and thinlto.
Run tests in all configurations:
(standalone, with devirtualization) * (gold, lld) * (lto, thinlto)

llvm-svn: 301016
2017-04-21 18:11:23 +00:00
Evgeniy Stepanov b9cb969d9c [cfi] Add explicit -flto in create-derivers test.
This is necessary to run the test suite in ThinLTO mode - otherwise
opt complains about an input file containing several modules.

llvm-svn: 300901
2017-04-20 21:44:37 +00:00
Evgeniy Stepanov a32c3e5b18 [cfi] Move one test under cross-dso/icall.
The test is using indirect calls.

llvm-svn: 300900
2017-04-20 21:44:35 +00:00
Evgeniy Stepanov 656bc5bb5c Fix sanitizer tests with LLVM_TOOL_LLD_BUILD=OFF.
Only depend on LLD if it is going to be built.

Re-land of r298174 which got reverted in r298287.

llvm-svn: 298753
2017-03-25 00:42:25 +00:00
Reid Kleckner 731bc9d2fe Use lld-link /nopdb to suppress PDB generation when DWARF is required
Fixes cfi/stats.cpp and asan/fuse-lld.cc on Windows.

llvm-svn: 298545
2017-03-22 19:49:29 +00:00
Reid Kleckner 81ee1a59ef XFAIL CFI stats test while LLD produces corrupt PDBs that confuse DIA
llvm-svn: 298476
2017-03-22 01:45:08 +00:00
Evgeniy Stepanov 3bf85d3124 Revert r298174, r298173, r298169, r298159.
Revert "Fix sanitizer tests with LLVM_TOOL_LLD_BUILD=OFF."
Revert "[asan] Remove gc-sections test with bfd."
Revert "[asan] Disable globals-gc test with ld.bfd."
Revert "[asan] Fix dead stripping of globals on Linux (compiler-rt)"

OOM in gold linker.

llvm-svn: 298287
2017-03-20 18:45:27 +00:00
Evgeniy Stepanov 0e6cb1925c Fix sanitizer tests with LLVM_TOOL_LLD_BUILD=OFF.
Only depend on LLD if it is going to be built.

llvm-svn: 298174
2017-03-18 00:25:43 +00:00
Evgeniy Stepanov 32f6b5129f [cfi] Disable bad-split test on win32.
It appears that the fix only helped Itanium ABI.

llvm-svn: 297775
2017-03-14 20:02:42 +00:00
Evgeniy Stepanov dd913de968 [cfi] Add test for type metadata split issue.
https://reviews.llvm.org/D30716

llvm-svn: 297771
2017-03-14 19:33:44 +00:00
Vedant Kumar 8f21c0e50a [cfi] Mark tests as xfailing on Darwin
This allows them to be run on other platforms, undoing damage from
r286902.

llvm-svn: 286904
2016-11-14 23:12:52 +00:00
Vedant Kumar 4f4e522b97 [cfi] Mark some tests as requiring additional support from the MachO writer
These tests need to be marked as unsupported on Darwin:

  http://lab.llvm.org:8080/green/job/clang-stage1-cmake-RA-expensive/1545

llvm-svn: 286902
2016-11-14 22:50:13 +00:00