Go to file
Matthew Malcomson 3bd8783207 libsanitizer: options: Add hwasan flags and argument parsing
These flags can't be used at the same time as any of the other
sanitizers.
We add an equivalent flag to -static-libasan in -static-libhwasan to
ensure static linking.

The -fsanitize=kernel-hwaddress option is for compiling targeting the
kernel.  This flag has defaults to match the LLVM implementation and
sets some other behaviors to work in the kernel (e.g. accounting for
the fact that the stack pointer will have 0xff in the top byte and to not
call the userspace library initialisation routines).
The defaults are that we do not sanitize variables on the stack and
always recover from a detected bug.

Since we are introducing a few more conflicts between sanitizer flags we
refactor the checking for such conflicts to use a helper function which
makes checking for such conflicts more easy and consistent.

We introduce a backend hook `targetm.memtag.can_tag_addresses` that
indicates to the mid-end whether a target has a feature like AArch64 TBI
where the top byte of an address is ignored.
Without this feature hwasan sanitization is not done.

gcc/ChangeLog:

	* common.opt (flag_sanitize_recover): Default for kernel
	hwaddress.
	(static-libhwasan): New cli option.
	* config/aarch64/aarch64.c (aarch64_can_tag_addresses): New.
	(TARGET_MEMTAG_CAN_TAG_ADDRESSES): New.
	* config/gnu-user.h (LIBHWASAN_EARLY_SPEC): hwasan equivalent of
	asan command line flags.
	* cppbuiltin.c (define_builtin_macros_for_compilation_flags):
	Add hwasan equivalent of __SANITIZE_ADDRESS__.
	* doc/invoke.texi: Document hwasan command line flags.
	* doc/tm.texi: Document new hook.
	* doc/tm.texi.in: Document new hook.
	* flag-types.h (enum sanitize_code): New sanitizer values.
	* gcc.c (STATIC_LIBHWASAN_LIBS): New macro.
	(LIBHWASAN_SPEC): New macro.
	(LIBHWASAN_EARLY_SPEC): New macro.
	(SANITIZER_EARLY_SPEC): Update to include hwasan.
	(SANITIZER_SPEC): Update to include hwasan.
	(sanitize_spec_function): Use hwasan options.
	* opts.c (finish_options): Describe conflicts between address
	sanitizers.
	(find_sanitizer_argument): New.
	(report_conflicting_sanitizer_options): New.
	(sanitizer_opts): Introduce new sanitizer flags.
	(common_handle_option): Add defaults for kernel sanitizer.
	* params.opt (hwasan--instrument-stack): New
	(hwasan-random-frame-tag): New
	(hwasan-instrument-allocas): New
	(hwasan-instrument-reads): New
	(hwasan-instrument-writes): New
	(hwasan-instrument-mem-intrinsics): New
	* target.def (HOOK_PREFIX): Add new hook.
	(can_tag_addresses): Add new hook under memtag prefix.
	* targhooks.c (default_memtag_can_tag_addresses): New.
	* targhooks.h (default_memtag_can_tag_addresses): New decl.
	* toplev.c (process_options): Ensure hwasan only on
	architectures that advertise the possibility.
2020-11-25 16:35:39 +00:00
config libsanitizer: Add option to bootstrap using HWASAN 2020-11-25 16:35:37 +00:00
contrib Daily bump. 2020-11-25 09:34:01 +00:00
fixincludes Daily bump. 2020-11-19 00:16:30 +00:00
gcc libsanitizer: options: Add hwasan flags and argument parsing 2020-11-25 16:35:39 +00:00
gnattools
gotools
include
INSTALL
intl
libada
libatomic
libbacktrace
libcc1
libcpp Daily bump. 2020-11-25 09:34:01 +00:00
libdecnumber
libffi
libgcc Daily bump. 2020-11-21 00:16:29 +00:00
libgfortran Daily bump. 2020-11-22 00:16:24 +00:00
libgo log/syslog: correct asm name for C function 2020-11-23 08:14:20 -08:00
libgomp Fix atomic_capture-1.f90 testcase 2020-11-25 13:55:45 +00:00
libhsail-rt
libiberty libsanitizer: Add option to bootstrap using HWASAN 2020-11-25 16:35:37 +00:00
libitm
libobjc
liboffloadmic
libphobos Daily bump. 2020-11-19 00:16:30 +00:00
libquadmath
libsanitizer libsanitizer: Only build libhwasan when targeting AArch64 2020-11-25 16:35:35 +00:00
libssp
libstdc++-v3 libstdc++: Fix silly typos [PR 97936] 2020-11-25 12:16:07 +00:00
libvtv
lto-plugin libsanitizer: Add option to bootstrap using HWASAN 2020-11-25 16:35:37 +00:00
maintainer-scripts
zlib
.dir-locals.el
.gitattributes
.gitignore Add .cache to git ignore. 2020-11-16 12:52:43 +01:00
ABOUT-NLS
ar-lib
ChangeLog Daily bump. 2020-11-24 00:16:44 +00:00
ChangeLog.jit
ChangeLog.tree-ssa
compile
config-ml.in
config.guess config.sub, config.guess : Import upstream 2020-11-07. 2020-11-23 19:30:01 +00:00
config.rpath
config.sub config.sub, config.guess : Import upstream 2020-11-07. 2020-11-23 19:30:01 +00:00
configure libsanitizer: Add option to bootstrap using HWASAN 2020-11-25 16:35:37 +00:00
configure.ac libsanitizer: Add option to bootstrap using HWASAN 2020-11-25 16:35:37 +00:00
COPYING
COPYING3
COPYING3.LIB
COPYING.LIB
COPYING.RUNTIME
depcomp
install-sh
libtool-ldflags
libtool.m4
lt~obsolete.m4
ltgcc.m4
ltmain.sh
ltoptions.m4
ltsugar.m4
ltversion.m4
MAINTAINERS
Makefile.def
Makefile.in
Makefile.tpl
missing
mkdep
mkinstalldirs
move-if-change
multilib.am
README
symlink-tree
test-driver
ylwrap

This directory contains the GNU Compiler Collection (GCC).

The GNU Compiler Collection is free software.  See the files whose
names start with COPYING for copying permission.  The manuals, and
some of the runtime libraries, are under different terms; see the
individual source files for details.

The directory INSTALL contains copies of the installation information
as HTML and plain text.  The source of this information is
gcc/doc/install.texi.  The installation information includes details
of what is included in the GCC sources and what files GCC installs.

See the file gcc/doc/gcc.texi (together with other files that it
includes) for usage and porting information.  An online readable
version of the manual is in the files gcc/doc/gcc.info*.

See http://gcc.gnu.org/bugs/ for how to report bugs usefully.

Copyright years on GCC source files may be listed using range
notation, e.g., 1987-2012, indicating that every year in the range,
inclusive, is a copyrightable year that could otherwise be listed
individually.