aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorAlexander Potapenko <glider@google.com>2013-02-04 20:08:29 +0000
committerMike Stump <mrs@gcc.gnu.org>2013-02-04 20:08:29 +0000
commitae526fe5cb554626a0b656c8c13ad1f66844fa43 (patch)
treec7b15cd7c8f45511faa73368fafacaa92984f621 /gcc
parent240d63482d9342b7ac8632ded9ec81785be5faa4 (diff)
downloadgcc-ae526fe5cb554626a0b656c8c13ad1f66844fa43.zip
gcc-ae526fe5cb554626a0b656c8c13ad1f66844fa43.tar.gz
gcc-ae526fe5cb554626a0b656c8c13ad1f66844fa43.tar.bz2
re PR sanitizer/55617 (static constructors are not being instrumented correctly on darwin)
2013-02-04 Alexander Potapenko <glider@google.com> Jack Howarth <howarth@bromo.med.uc.edu> Jakub Jelinek <jakub@redhat.com> PR sanitizer/55617 * config/darwin.c (sort_ctor_records): Stabilized qsort on constructor priority by using original position. (finalize_ctors): New routine to sort constructors by priority before use in assemble_integer. (machopic_asm_out_constructor): Use finalize_ctors if needed. Co-Authored-By: Jack Howarth <howarth@bromo.med.uc.edu> Co-Authored-By: Jakub Jelinek <jakub@redhat.com> From-SVN: r195735
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog11
-rw-r--r--gcc/config/darwin.c51
2 files changed, 58 insertions, 4 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index cc67ff9..bfb857d 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,14 @@
+2013-02-04 Alexander Potapenko <glider@google.com>
+ Jack Howarth <howarth@bromo.med.uc.edu>
+ Jakub Jelinek <jakub@redhat.com>
+
+ PR sanitizer/55617
+ * config/darwin.c (sort_ctor_records): Stabilized qsort
+ on constructor priority by using original position.
+ (finalize_ctors): New routine to sort constructors by
+ priority before use in assemble_integer.
+ (machopic_asm_out_constructor): Use finalize_ctors if needed.
+
2013-02-04 Jakub Jelinek <jakub@redhat.com>
PR libstdc++/54314
diff --git a/gcc/config/darwin.c b/gcc/config/darwin.c
index 0c79139..f1bf24a 100644
--- a/gcc/config/darwin.c
+++ b/gcc/config/darwin.c
@@ -83,6 +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 {
+ rtx symbol;
+ int priority; /* constructor priority */
+ int position; /* original position */
+} ctor_record;
+
+static GTY(()) vec<ctor_record, va_gc> *ctors = 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_
functions). */
@@ -1708,15 +1716,48 @@ 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)};
+
+ vec_safe_push (ctors, new_elt);
+
+ if (! MACHOPIC_INDIRECT)
+ fprintf (asm_out_file, ".reference .constructors_used\n");
+}
+
+static int
+sort_ctor_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)
+ return 1;
+ if (ca->priority < cb->priority)
+ return -1;
+ if (ca->position > cb->position)
+ return 1;
+ if (ca->position < cb->position)
+ return -1;
+ return 0;
+}
+
+static void
+finalize_ctors()
+{
+ unsigned int i;
+ ctor_record *elt;
+
if (MACHOPIC_INDIRECT)
switch_to_section (darwin_sections[mod_init_section]);
else
switch_to_section (darwin_sections[constructor_section]);
- assemble_align (POINTER_SIZE);
- assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
- if (! MACHOPIC_INDIRECT)
- fprintf (asm_out_file, ".reference .constructors_used\n");
+ if (vec_safe_length (ctors) > 1)
+ ctors->qsort (sort_ctor_records);
+ FOR_EACH_VEC_SAFE_ELT (ctors, i, elt)
+ {
+ assemble_align (POINTER_SIZE);
+ assemble_integer (elt->symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
+ }
}
void
@@ -2762,6 +2803,8 @@ darwin_file_start (void)
void
darwin_file_end (void)
{
+ if (!vec_safe_is_empty (ctors))
+ finalize_ctors();
machopic_finish (asm_out_file);
if (strcmp (lang_hooks.name, "GNU C++") == 0)
{