From 753706ed4724154ba63df77e02e0024ffecdcb46 Mon Sep 17 00:00:00 2001 From: Georg-Johann Lay Date: Tue, 22 Aug 2017 10:32:36 +0000 Subject: [PATCH] backport: re PR lto/81487 ([mingw32] ld.exe: error: asprintf failed) lto-plugin/ Backport from 2017-07-26 gcc-7-branch r250562. PR lto/81487 * lto-plugin.c (claim_file_handler): Use xasprintf instead of asprintf. [hi!=0]: Swap hi and lo arguments supplied to xasprintf. gcc/ Backport from 2017-07-26 gcc-7-branch r250562. PR 81487 * tree-ssa-structalias.c (alias_get_name): Use xasprintf instead of asprintf. From-SVN: r251272 --- gcc/ChangeLog | 8 ++++++++ gcc/tree-ssa-structalias.c | 21 +++++++-------------- lto-plugin/ChangeLog | 9 +++++++++ lto-plugin/lto-plugin.c | 13 ++++++------- 4 files changed, 30 insertions(+), 21 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index fc3d5a57e5e8..bf7083329361 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2017-08-22 Georg-Johann Lay + + Backport from 2017-07-26 gcc-7-branch r250562. + + PR 81487 + * tree-ssa-structalias.c (alias_get_name): Use xasprintf instead + of asprintf. + 2017-08-22 Georg-Johann Lay Backport from trunk r247719. diff --git a/gcc/tree-ssa-structalias.c b/gcc/tree-ssa-structalias.c index d1eaae2f5c42..10231933b2a6 100644 --- a/gcc/tree-ssa-structalias.c +++ b/gcc/tree-ssa-structalias.c @@ -2864,7 +2864,6 @@ alias_get_name (tree decl) { const char *res = NULL; char *temp; - int num_printed = 0; if (!dump_file) return "NULL"; @@ -2873,14 +2872,11 @@ alias_get_name (tree decl) { res = get_name (decl); if (res) - num_printed = asprintf (&temp, "%s_%u", res, SSA_NAME_VERSION (decl)); + temp = xasprintf ("%s_%u", res, SSA_NAME_VERSION (decl)); else - num_printed = asprintf (&temp, "_%u", SSA_NAME_VERSION (decl)); - if (num_printed > 0) - { - res = ggc_strdup (temp); - free (temp); - } + temp = xasprintf ("_%u", SSA_NAME_VERSION (decl)); + res = ggc_strdup (temp); + free (temp); } else if (DECL_P (decl)) { @@ -2891,12 +2887,9 @@ alias_get_name (tree decl) res = get_name (decl); if (!res) { - num_printed = asprintf (&temp, "D.%u", DECL_UID (decl)); - if (num_printed > 0) - { - res = ggc_strdup (temp); - free (temp); - } + temp = xasprintf ("D.%u", DECL_UID (decl)); + res = ggc_strdup (temp); + free (temp); } } } diff --git a/lto-plugin/ChangeLog b/lto-plugin/ChangeLog index 39788af6c8b4..7a65539d7f8c 100644 --- a/lto-plugin/ChangeLog +++ b/lto-plugin/ChangeLog @@ -1,3 +1,12 @@ +2017-08-22 Georg-Johann Lay + + Backport from 2017-07-26 gcc-7-branch r250562. + + PR lto/81487 + * lto-plugin.c (claim_file_handler): Use xasprintf instead of + asprintf. + [hi!=0]: Swap hi and lo arguments supplied to xasprintf. + 2016-06-03 Release Manager * GCC 5.4.0 released. diff --git a/lto-plugin/lto-plugin.c b/lto-plugin/lto-plugin.c index 8d957402ba66..03ebb00aa23f 100644 --- a/lto-plugin/lto-plugin.c +++ b/lto-plugin/lto-plugin.c @@ -920,17 +920,16 @@ claim_file_handler (const struct ld_plugin_input_file *file, int *claimed) if (file->offset != 0) { - char *objname; /* We pass the offset of the actual file, not the archive header. Can't use PRIx64, because that's C99, so we have to print the - 64-bit hex int as two 32-bit ones. */ - int lo, hi, t; + 64-bit hex int as two 32-bit ones. Use xasprintf instead of + asprintf because asprintf doesn't work as expected on some older + mingw32 hosts. */ + int lo, hi; lo = file->offset & 0xffffffff; hi = ((int64_t)file->offset >> 32) & 0xffffffff; - t = hi ? asprintf (&objname, "%s@0x%x%08x", file->name, lo, hi) - : asprintf (&objname, "%s@0x%x", file->name, lo); - check (t >= 0, LDPL_FATAL, "asprintf failed"); - lto_file.name = objname; + lto_file.name = hi ? xasprintf ("%s@0x%x%08x", file->name, hi, lo) + : xasprintf ("%s@0x%x", file->name, lo); } else { -- 2.47.2