aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorAlexander Potapenko <glider@google.com>2013-02-11 22:36:23 +0000
committerMike Stump <mrs@gcc.gnu.org>2013-02-11 22:36:23 +0000
commit6a52ccb3b897320a90cc86709249db167605a42f (patch)
tree4c88f130401ee1abfa6d0b6727716bc58e18cfcc /gcc
parent913bd57d50235b3af93b6dbefbc9d94cd1fd5005 (diff)
downloadgcc-6a52ccb3b897320a90cc86709249db167605a42f.zip
gcc-6a52ccb3b897320a90cc86709249db167605a42f.tar.gz
gcc-6a52ccb3b897320a90cc86709249db167605a42f.tar.bz2
re PR sanitizer/55617 (static constructors are not being instrumented correctly on darwin)
2013-02-11 Alexander Potapenko <glider@google.com> Jack Howarth <howarth@bromo.med.uc.edu> Jakub Jelinek <jakub@redhat.com> PR sanitizer/55617 * config/darwin.c (cdtor_record): Rename ctor_record. (sort_cdtor_records): Rename sort_ctor_records. (finalize_dtors): New routine to sort destructors by priority before use in assemble_integer. (machopic_asm_out_destructor): Use finalize_dtors if needed. testsuite: 2013-02-11 Alexander Potapenko <glider@google.com> Jack Howarth <howarth@bromo.med.uc.edu> Jakub Jelinek <jakub@redhat.com> PR sanitizer/55617 * g++.dg/asan/pr55617.C: Run on all targets. Co-Authored-By: Jack Howarth <howarth@bromo.med.uc.edu> Co-Authored-By: Jakub Jelinek <jakub@redhat.com> From-SVN: r195956
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog11
-rw-r--r--gcc/config/darwin.c64
-rw-r--r--gcc/testsuite/ChangeLog7
-rw-r--r--gcc/testsuite/g++.dg/asan/pr55617.C2
4 files changed, 61 insertions, 23 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 00d0784..1337da8 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,14 @@
+2013-02-11 Alexander Potapenko <glider@google.com>
+ Jack Howarth <howarth@bromo.med.uc.edu>
+ Jakub Jelinek <jakub@redhat.com>
+
+ PR sanitizer/55617
+ * config/darwin.c (cdtor_record): Rename ctor_record.
+ (sort_cdtor_records): Rename sort_ctor_records.
+ (finalize_dtors): New routine to sort destructors by
+ priority before use in assemble_integer.
+ (machopic_asm_out_destructor): Use finalize_dtors if needed.
+
2013-02-11 Uros Bizjak <ubizjak@gmail.com>
PR rtl-optimization/56275
diff --git a/gcc/config/darwin.c b/gcc/config/darwin.c
index f1bf24a..a049a5d 100644
--- a/gcc/config/darwin.c
+++ b/gcc/config/darwin.c
@@ -83,13 +83,14 @@ along with GCC; see the file COPYING3. If not see
kernel) the stubs might still be required, and this will be set true. */
int darwin_emit_branch_islands = false;
-typedef struct GTY(()) ctor_record {
+typedef struct GTY(()) cdtor_record {
rtx symbol;
- int priority; /* constructor priority */
+ int priority; /* [con/de]structor priority */
int position; /* original position */
-} ctor_record;
+} cdtor_record;
-static GTY(()) vec<ctor_record, va_gc> *ctors = NULL;
+static GTY(()) vec<cdtor_record, va_gc> *ctors = NULL;
+static GTY(()) vec<cdtor_record, va_gc> *dtors = NULL;
/* A flag to determine whether we are running c++ or obj-c++. This has to be
settable from non-c-family contexts too (i.e. we can't use the c_dialect_
@@ -1716,7 +1717,7 @@ machopic_select_rtx_section (enum machine_mode mode, rtx x,
void
machopic_asm_out_constructor (rtx symbol, int priority ATTRIBUTE_UNUSED)
{
- ctor_record new_elt = {symbol, priority, vec_safe_length (ctors)};
+ cdtor_record new_elt = {symbol, priority, vec_safe_length (ctors)};
vec_safe_push (ctors, new_elt);
@@ -1724,27 +1725,38 @@ machopic_asm_out_constructor (rtx symbol, int priority ATTRIBUTE_UNUSED)
fprintf (asm_out_file, ".reference .constructors_used\n");
}
+void
+machopic_asm_out_destructor (rtx symbol, int priority ATTRIBUTE_UNUSED)
+{
+ cdtor_record new_elt = {symbol, priority, vec_safe_length (dtors)};
+
+ vec_safe_push (dtors, new_elt);
+
+ if (! MACHOPIC_INDIRECT)
+ fprintf (asm_out_file, ".reference .destructors_used\n");
+}
+
static int
-sort_ctor_records (const void * a, const void * b)
+sort_cdtor_records (const void * a, const void * b)
{
- const ctor_record *ca = (const ctor_record *)a;
- const ctor_record *cb = (const ctor_record *)b;
- if (ca->priority > cb->priority)
+ const cdtor_record *cda = (const cdtor_record *)a;
+ const cdtor_record *cdb = (const cdtor_record *)b;
+ if (cda->priority > cdb->priority)
return 1;
- if (ca->priority < cb->priority)
+ if (cda->priority < cdb->priority)
return -1;
- if (ca->position > cb->position)
+ if (cda->position > cdb->position)
return 1;
- if (ca->position < cb->position)
+ if (cda->position < cdb->position)
return -1;
return 0;
}
static void
-finalize_ctors()
+finalize_ctors ()
{
unsigned int i;
- ctor_record *elt;
+ cdtor_record *elt;
if (MACHOPIC_INDIRECT)
switch_to_section (darwin_sections[mod_init_section]);
@@ -1752,7 +1764,7 @@ finalize_ctors()
switch_to_section (darwin_sections[constructor_section]);
if (vec_safe_length (ctors) > 1)
- ctors->qsort (sort_ctor_records);
+ ctors->qsort (sort_cdtor_records);
FOR_EACH_VEC_SAFE_ELT (ctors, i, elt)
{
assemble_align (POINTER_SIZE);
@@ -1760,18 +1772,24 @@ finalize_ctors()
}
}
-void
-machopic_asm_out_destructor (rtx symbol, int priority ATTRIBUTE_UNUSED)
+static void
+finalize_dtors ()
{
+ unsigned int i;
+ cdtor_record *elt;
+
if (MACHOPIC_INDIRECT)
switch_to_section (darwin_sections[mod_term_section]);
else
switch_to_section (darwin_sections[destructor_section]);
- assemble_align (POINTER_SIZE);
- assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
- if (! MACHOPIC_INDIRECT)
- fprintf (asm_out_file, ".reference .destructors_used\n");
+ if (vec_safe_length (dtors) > 1)
+ dtors->qsort (sort_cdtor_records);
+ FOR_EACH_VEC_SAFE_ELT (dtors, i, elt)
+ {
+ assemble_align (POINTER_SIZE);
+ assemble_integer (elt->symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
+ }
}
void
@@ -2804,7 +2822,9 @@ void
darwin_file_end (void)
{
if (!vec_safe_is_empty (ctors))
- finalize_ctors();
+ finalize_ctors ();
+ if (!vec_safe_is_empty (dtors))
+ finalize_dtors ();
machopic_finish (asm_out_file);
if (strcmp (lang_hooks.name, "GNU C++") == 0)
{
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index dce413d..034bbd2 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,10 @@
+2013-02-11 Alexander Potapenko <glider@google.com>
+ Jack Howarth <howarth@bromo.med.uc.edu>
+ Jakub Jelinek <jakub@redhat.com>
+
+ PR sanitizer/55617
+ * g++.dg/asan/pr55617.C: Run on all targets.
+
2013-02-11 Uros Bizjak <ubizjak@gmail.com>
PR rtl-optimization/56275
diff --git a/gcc/testsuite/g++.dg/asan/pr55617.C b/gcc/testsuite/g++.dg/asan/pr55617.C
index 9f50a79..02f0dae 100644
--- a/gcc/testsuite/g++.dg/asan/pr55617.C
+++ b/gcc/testsuite/g++.dg/asan/pr55617.C
@@ -1,4 +1,4 @@
-// { dg-do run { target { i?86-*-darwin* x86_64-*-darwin* } } }
+// { dg-do run }
struct c18 {
virtual void bar() { }