This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Implement -fsanitize=object-size


On Fri, Oct 10, 2014 at 12:04:08PM +0200, Marek Polacek wrote:
> I couldn't test bootstrap-ubsan, because of error:
> /home/polacek/x/trunk/prev-x86_64-unknown-linux-gnu/libsanitizer/ubsan/.libs/libubsan.a(ubsan_init.o):
> .preinit_array section is not allowed in DSO
> but I remember that the previous version of the patch passed fine.

We build (intentionally) both libubsan.so.* objects and libubsan.a
objects with -fPIC, but don't build the latter with -DPIC.  I guess
we need now, with -static-libubsan libubsan.a is linked into shared
libraries statically and we definitely can't use .preinit_array
in that case.

So, I think (untested) something like:

2014-10-10  Jakub Jelinek  <jakub@redhat.com>

	* ubsan/Makefile.am (DEFS): Add -DPIC.
	* ubsan/Makefile.in: Regenerated.

--- libsanitizer/ubsan/Makefile.am	2014-09-24 11:08:04.183026156 +0200
+++ libsanitizer/ubsan/Makefile.am	2014-10-10 12:15:19.124247283 +0200
@@ -3,7 +3,7 @@ AM_CPPFLAGS = -I $(top_srcdir) -I $(top_
 # May be used by toolexeclibdir.
 gcc_version := $(shell cat $(top_srcdir)/../gcc/BASE-VER)
 
-DEFS = -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
+DEFS = -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -DPIC
 AM_CXXFLAGS = -Wall -W -Wno-unused-parameter -Wwrite-strings -pedantic -Wno-long-long  -fPIC -fno-builtin -fno-exceptions -fno-rtti -fomit-frame-pointer -funwind-tables -fvisibility=hidden -Wno-variadic-macros
 AM_CXXFLAGS += $(LIBSTDCXX_RAW_CXX_CXXFLAGS)
 ACLOCAL_AMFLAGS = -I m4

should fix this.

> 2014-10-09  Marek Polacek  <polacek@redhat.com>

Check the date ;)

> 	* asan.c (pass_sanopt::execute): Handle IFN_UBSAN_OBJECT_SIZE.
> 	* doc/invoke.texi: Document -fsanitize=object-size.
> 	* flag-types.h (enum sanitize_code): Add SANITIZE_OBJECT_SIZE and
> 	or it into SANITIZE_UNDEFINED.
> 	* gimple-fold.c (gimple_fold_call): Optimize IFN_UBSAN_OBJECT_SIZE.
> 	* internal-fn.c (expand_UBSAN_OBJECT_SIZE): New function.
> 	* internal-fn.def (UBSAN_OBJECT_SIZE): Define.
> 	* opts.c (common_handle_option): Handle -fsanitize=object-size.
> 	* ubsan.c: Include "tree-object-size.h".

I'd avoid the ""s.

> --- gcc/gimple-fold.c
> +++ gcc/gimple-fold.c
> @@ -2662,6 +2662,19 @@ gimple_fold_call (gimple_stmt_iterator *gsi, bool inplace)
>  					gimple_call_arg (stmt, 1),
>  					gimple_call_arg (stmt, 2));
>  	  break;
> +        case IFN_UBSAN_OBJECT_SIZE:
> +	  if (integer_all_onesp (gimple_call_arg (stmt, 2))

Formatting on the case line, there should be tab.

> +
> +  gcc_assert (TREE_CODE (size) == INTEGER_CST);
> +  /* See if we can discard the check.  */
> +  if (integer_all_onesp (size))
> +    /* Yes, __builtin_object_size couldn't determine the
> +       object size.  */;

I'd just treat TREE_CODE (size) != INTEGER_CST
the same as integer_all_onesp.  It is very likely you'll get
an INTEGER_CST there, but I'd be afraid if somebody disables ccp, forwprop
and similar optimizations that if you are unlucky you might actually have
an SSA_NAME there instead.

Ok with those changes.

After commit, please update gcc-5/changes.html.  Thanks.

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]