From ecf7069f1b70ba21063e1b09c8505807acb3f1de Mon Sep 17 00:00:00 2001 From: Nick Clifton Date: Mon, 11 Dec 2017 10:36:08 +0000 Subject: [PATCH] Do not generate notes when there is no output file. Resolves: #1523875 --- annobin-empty-input-filename.patch | 2 +- annobin-lto-filename.patch | 60 ++++++++++++++++++++++++++++++ annobin.spec | 12 +++++- 3 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 annobin-lto-filename.patch diff --git a/annobin-empty-input-filename.patch b/annobin-empty-input-filename.patch index ab2de3c..fa95df6 100644 --- a/annobin-empty-input-filename.patch +++ b/annobin-empty-input-filename.patch @@ -11,7 +11,7 @@ diff -rup annobin.orig/plugin/annobin.cc annobin-2.5.1/plugin/annobin.cc + { + /* The name can be empty if we are receiving the source code + from a pipe. In this case, we invent our own name. */ -+ name = "piped_input"; ++ name = (char *) "piped_input"; + } + if (global_file_name_symbols) diff --git a/annobin-lto-filename.patch b/annobin-lto-filename.patch new file mode 100644 index 0000000..ca56954 --- /dev/null +++ b/annobin-lto-filename.patch @@ -0,0 +1,60 @@ +--- annobin.orig/plugin/annobin.cc 2017-12-11 10:25:28.034276686 +0000 ++++ annobin-2.5.1/plugin/annobin.cc 2017-12-11 10:26:40.964423113 +0000 +@@ -179,6 +179,9 @@ annobin_output_note (const void * name, + { + unsigned i; + ++ if (asm_out_file == NULL) ++ return; ++ + if (type == NT_GNU_BUILD_ATTRIBUTE_FUNC + || type == NT_GNU_BUILD_ATTRIBUTE_OPEN) + { +@@ -512,6 +515,9 @@ annobin_create_function_notes (void * gc + if (! annobin_enable_static_notes) + return; + ++ if (asm_out_file == NULL) ++ return; ++ + annobin_target_specific_function_notes (); + + if (global_stack_prot_option != flag_stack_protect) +@@ -592,7 +598,18 @@ annobin_create_global_notes (void * gcc_ + + if (! annobin_enable_static_notes) + return; +- ++ ++ if (asm_out_file == NULL) ++ { ++ /* This happens during LTO compilation. Compilation is triggered ++ before any output file has been opened. Since we do not have ++ the file handle we cannot emit any notes. On the other hand, ++ the recompilation process will repeat later on with a real ++ output file and so the notes can be generated then. */ ++ annobin_inform (1, "Output file not available - unable to generate notes"); ++ return; ++ } ++ + /* Record global information. + Note - we do this here, rather than in plugin_init() as some + information, PIC status or POINTER_SIZE, may not be initialised +@@ -629,6 +646,7 @@ annobin_create_global_notes (void * gcc_ + /* We need a filename, so invent one. */ + annobin_current_filename = (char *) "unknown_source"; + } ++ + if (global_file_name_symbols) + fprintf (asm_out_file, ".global %s\n", annobin_current_filename); + fprintf (asm_out_file, ".type %s STT_OBJECT\n", annobin_current_filename); +@@ -718,6 +736,9 @@ annobin_create_loader_notes (void * gcc_ + if (! annobin_enable_dynamic_notes) + return; + ++ if (asm_out_file == NULL) ++ return; ++ + if (annobin_enable_stack_size_notes && annobin_total_static_stack_usage) + { + annobin_inform (1, "Recording total static usage of %ld", annobin_total_static_stack_usage); diff --git a/annobin.spec b/annobin.spec index dbb74fe..9fec592 100644 --- a/annobin.spec +++ b/annobin.spec @@ -1,7 +1,7 @@ Name: annobin Summary: Binary annotation plugin for GCC Version: 2.5.1 -Release: 4%{?dist} +Release: 5%{?dist} License: GPLv3+ URL: https://fedoraproject.org/wiki/Toolchain/Watermark @@ -23,6 +23,11 @@ Patch1: funname.patch # Lifetime: Fixed in 2.5.2 Patch2: annobin-empty-input-filename.patch +# Purpose: Fixes a bug where compiling with LTO enabled would result in the +# plugin being called with no output file handle available. +# Lifetime: Fixed in 2.5.2 +Patch3: annobin-lto-filename.patch + # This is a gcc plugin, hence gcc is required. Requires: gcc @@ -81,7 +86,10 @@ make check #--------------------------------------------------------------------------------- %changelog -* Fri Dec 08 2017 Florian Weimer - 2.5.1-4 +* Mon Dec 11 2017 Nick Clifton - 2.5.1-5 +- Do not generate notes when there is no output file. (#1523875) + +* Fri Dec 08 2017 Nick Clifton - 2.5.1-4 - Invent an input filename when reading from a pipe. (#1523401) * Thu Nov 30 2017 Florian Weimer - 2.5.1-3