diff mbox

PR lto/61048 Write/read option -fsanitize to/from object files

Message ID 543E891C.4080303@samsung.com
State New
Headers show

Commit Message

Ilya Palachev Oct. 15, 2014, 2:47 p.m. UTC
Hi all,

The attached patch fixes PR lto/61048.

The basic idea is to write option -fsanitize to existing ELF section 
.gnu.lto_.opts in object files and then read it in lto-wrapper.

On 15.10.2014 12:46, Richard Biener wrote:
> You need to handle them in lto-opts.c and output them to the existing option
> section.

2 minor changes are added to existing function that write options (in 
lto-opts.c) and then read them from object files (lto-wrapper.c).

The patch was bootstrapped and regtested on x86_64-unknown-linux-gnu.

Ok for trunk?

Best regards,
Ilya Palachev

Comments

Richard Biener Oct. 16, 2014, 11:38 a.m. UTC | #1
On Wed, Oct 15, 2014 at 4:47 PM, Ilya Palachev <i.palachev@samsung.com> wrote:
> Hi all,
>
> The attached patch fixes PR lto/61048.
>
> The basic idea is to write option -fsanitize to existing ELF section
> .gnu.lto_.opts in object files and then read it in lto-wrapper.
>
> On 15.10.2014 12:46, Richard Biener wrote:
>>
>> You need to handle them in lto-opts.c and output them to the existing
>> option
>> section.
>
>
> 2 minor changes are added to existing function that write options (in
> lto-opts.c) and then read them from object files (lto-wrapper.c).
>
> The patch was bootstrapped and regtested on x86_64-unknown-linux-gnu.
>
> Ok for trunk?

Ok.

Note that for mismatched options you'll now get the "first" chosen.
Which could be -fno-sanitize=address.  Also if you build one file
with -fsanitize=address and one with -fsanitize=undefined you'll
get either but not both enabled.

So the patch works for the simple cases but it will likely require
more complex handling in lto-wrapper.c:merge_and_complain
to do something sensible for mismatches (and not treat
-fsanitize=address equal to -fsanitize=undefined).

Btw, similar merging issues probably exist for -fsanitize-recover,
-fsanitize-undefined-trap-on-error, or do they apply during
instrumentation already?

Thanks,
Richard.

> Best regards,
> Ilya Palachev
diff mbox

Patch

From e3d1e1dc6d64b04fb81d882528614f1fc37cfa5f Mon Sep 17 00:00:00 2001
From: Ilya Palachev <i.palachev@samsung.com>
Date: Wed, 15 Oct 2014 16:21:50 +0400
Subject: [PATCH] Write/read option -fsanitize to/from object files

gcc/

2014-10-15  Ilya Palachev  <i.palachev@samsung.com>

	* lto-opts.c (lto_write_options): Enable writing of option
	-fsanitize to object files.
	* lto-wrapper.c (run_gcc): Enable reading of option -fsanitize
	from object files.

gcc/testsuite/

2014-10-15  Ilya Palachev  <i.palachev@samsung.com>

	* g++.dg/lto/pr61048_0.C: New test from bugzilla.
---
 gcc/lto-opts.c                       | 10 +++++++++-
 gcc/lto-wrapper.c                    |  1 +
 gcc/testsuite/g++.dg/lto/pr61048_0.C |  9 +++++++++
 3 files changed, 19 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/lto/pr61048_0.C

diff --git a/gcc/lto-opts.c b/gcc/lto-opts.c
index ceccb6f..abeca1c 100644
--- a/gcc/lto-opts.c
+++ b/gcc/lto-opts.c
@@ -178,7 +178,15 @@  lto_write_options (void)
          which includes things like -o and -v or -fhelp for example.
 	 We do not need those.  Also drop all diagnostic options.  */
       if (cl_options[option->opt_index].flags & (CL_DRIVER|CL_WARNING))
-	continue;
+        switch (option->opt_index)
+          {
+          /* Option -fsanitize should not be dropped, since otherwise
+	     sanitizer builtins will not be initialized. See PR61048.  */
+          case OPT_fsanitize_:
+            break;
+          default:
+            continue;
+          }
 
       for (j = 0; j < option->canonical_option_num_elements; ++j)
 	append_to_collect_gcc_options (&temporary_obstack, &first_p,
diff --git a/gcc/lto-wrapper.c b/gcc/lto-wrapper.c
index 8033b15..43d31d7 100644
--- a/gcc/lto-wrapper.c
+++ b/gcc/lto-wrapper.c
@@ -514,6 +514,7 @@  run_gcc (unsigned argc, char *argv[])
 	case OPT_fwrapv:
 	case OPT_ftrapv:
 	case OPT_fstrict_overflow:
+	case OPT_fsanitize_:
 	case OPT_O:
 	case OPT_Ofast:
 	case OPT_Og:
diff --git a/gcc/testsuite/g++.dg/lto/pr61048_0.C b/gcc/testsuite/g++.dg/lto/pr61048_0.C
new file mode 100644
index 0000000..40ae097
--- /dev/null
+++ b/gcc/testsuite/g++.dg/lto/pr61048_0.C
@@ -0,0 +1,9 @@ 
+// { dg-lto-do link }
+// { dg-lto-options {{-fsanitize=address -flto}} }
+
+#include <iostream>
+int main ()
+{
+  int *i = reinterpret_cast<int*> (0xC1000000);
+  std::cout << *i << std::endl;
+}
-- 
2.1.1