]> sourceware.org Git - annobin.git/commitdiff
Add function-verbose option to print messages when function notes are created.
authorNick Clifton <nickc@redhat.com>
Tue, 20 Mar 2018 11:18:42 +0000 (11:18 +0000)
committerNick Clifton <nickc@redhat.com>
Tue, 20 Mar 2018 11:18:42 +0000 (11:18 +0000)
Handle dwarf_version being -1.
Put the end-of-function symbol in the same section as the function itself.
Add function-sections-test.

doc/annobin.info
doc/annobin.texi
plugin/annobin.cc
plugin/powerpc.annobin.cc
plugin/x86_64.annobin.cc
tests/Makefile.am
tests/Makefile.in
tests/hello.c

index a169070b2d0ab86f166c8c2851af1c537caa8f50..ab6f072361b423c1ebdb31664d683673d335146e 100644 (file)
@@ -137,6 +137,11 @@ after the plugin itself is mentioned.  The options are:
      Report the actions that the plugin is taking.  If invoked for a
      second time on the command line the plugin will be very verbose.
 
+'function-verbose'
+     Report the generation of function specific notes.  This indicates
+     that the named function was compiled with different options from
+     those that were globally enabled.
+
 'no-dynamic-notes'
 'dynamic-notes'
      Do not, or do, record information for the dynamic loader.  The
@@ -229,7 +234,7 @@ File: annobin.info,  Node: The Version Encoding,  Next: The PIC Encoding,  Up: C
 
 The 'version' note encodes the version of the Watermark specification
 used and the version of the tool used to generate the notes.  Typically
-these will both be 3.
+the protocol version will be 3 and the plugin version will be 5.
 
 \1f
 File: annobin.info,  Node: The PIC Encoding,  Next: The GOW Encoding,  Prev: The Version Encoding,  Up: Checking
@@ -1279,17 +1284,17 @@ Tag Table:
 Node: Top\7f706
 Node: Introduction\7f1584
 Node: Invocation\7f3686
-Node: Checking\7f7683
-Node: The Version Encoding\7f10027
-Node: The PIC Encoding\7f10372
-Node: The GOW Encoding\7f11001
-Node: The CF Encoding\7f12448
-Node: The CET Encoding\7f13518
-Node: Using\7f14286
-Node: Who Built Me\7f14801
-Node: ABI Checking\7f17579
-Node: Hardening Checks\7f19707
-Node: Checking Archives\7f23549
-Node: GNU FDL\7f25987
+Node: Checking\7f7883
+Node: The Version Encoding\7f10227
+Node: The PIC Encoding\7f10615
+Node: The GOW Encoding\7f11244
+Node: The CF Encoding\7f12691
+Node: The CET Encoding\7f13761
+Node: Using\7f14529
+Node: Who Built Me\7f15044
+Node: ABI Checking\7f17822
+Node: Hardening Checks\7f19950
+Node: Checking Archives\7f23792
+Node: GNU FDL\7f26230
 \1f
 End Tag Table
index 3896c204a8a513c5c340db0326823b54da096e19..5a24b543cd768aba3db44c98a4eaa1ba2f34fbce 100644 (file)
@@ -187,6 +187,11 @@ in addition to whatever else the plugin has been instructed to do.
 Report the actions that the plugin is taking.  If invoked for a second
 time on the command line the plugin will be very verbose.
 
+@item function-verbose
+Report the generation of function specific notes.  This indicates that
+the named function was compiled with different options from those that
+were globally enabled.
+
 @item no-dynamic-notes
 @itemx dynamic-notes
 Do not, or do, record information for the dynamic loader.  The default
index 016a7d2f45672e5627b024dc0a8d972fd4267185..b580c1caecf2baaaaca175a9ec00aa2d00f811de 100644 (file)
@@ -51,7 +51,10 @@ static unsigned long  stack_threshold = DEFAULT_THRESHOLD;
 /* Internal variable, used by target specific parts of the annobin plugin as well
    as this generic part.  True if the object file being generated is for a 64-bit
    target.  */
-bool           annobin_is_64bit = false;
+bool                  annobin_is_64bit = false;
+
+/* True if the creation of function specific notes should be reported.  */
+static bool           annobin_function_verbose = false;
 
 /* True if notes in the .note.gnu.property section should be produced.  */
 static bool           annobin_enable_dynamic_notes = true;
@@ -82,6 +85,7 @@ static const char *   help_string =  N_("Supported options:\n\
    help                   Print out this information\n\
    version                Print out the version of the plugin\n\
    verbose                Be talkative about what is going on\n\
+   function-verbose       Report the creation of function specific notes\n\
    [no-]dynamic-notes     Do [do not] create dynamic notes (default: do)\n\
    [no-]static-notes      Do [do not] create static notes (default: do)\n\
    [no-]global-file-syms  Create global [or local] file name symbols (default: local)\n\
@@ -199,12 +203,15 @@ annobin_output_note (const char * name,
   if (asm_out_file == NULL)
     return;
 
-  if (type == FUNC
-      || type == OPEN)
+  if (annobin_function_verbose && type == FUNC)
     {
-      fprintf (asm_out_file, "\t.pushsection %s\n", GNU_BUILD_ATTRS_SECTION_NAME);    
+      if (desc_is_string)
+       annobin_inform (0, "create function specific note for: %s: %s", desc1, name_description);
     }
 
+  if (type == FUNC || type == OPEN)
+    fprintf (asm_out_file, "\t.pushsection %s\n", GNU_BUILD_ATTRS_SECTION_NAME);
+
   if (name == NULL)
     {
       if (namesz)
@@ -364,14 +371,11 @@ annobin_output_note (const char * name,
        }
     }
 
-  if (type == FUNC
-      || type == OPEN)
-    {
-      fprintf (asm_out_file, "\t.popsection\n");
-      fflush (asm_out_file);
-    }
+  if (type == FUNC || type == OPEN)
+    fprintf (asm_out_file, "\t.popsection\n");
 
   fprintf (asm_out_file, "\n");
+  fflush (asm_out_file);
 
   ++ annobin_note_count;
 }
@@ -440,7 +444,7 @@ annobin_output_numeric_note (const char     numeric_type,
 {
   unsigned i;
   char buffer [32];
-  
+
   sprintf (buffer, "GA%c%c", NUMERIC, numeric_type);
 
   if (value == 0)
@@ -527,11 +531,23 @@ compute_GOWall_options (void)
   else
     val |= (debug_info_level << 4);
 
-  if (dwarf_version < 0 || dwarf_version > 7)
-    annobin_inform (0, "ICE: unknown dwarf version level %d\n", dwarf_version);
+  if (dwarf_version < 2)
+    {
+      /* Apparently it is possible for dwarf_version to be -1.  Not sure how
+        this can happen, but handle it anyway.  Since DWARF prior to v2 is
+        deprecated, we use 2 as the version level.  */
+      val |= (2 << 6);
+      annobin_inform (1, "dwarf version level %d recorded as 2\n", dwarf_version);
+    }
+  else if (dwarf_version > 7)
+    {
+      /* FIXME: We only have 3 bits to record the debug level...  */
+      val |= (7 << 6);
+      annobin_inform (1, "dwarf version level %d recorded as 7\n", dwarf_version);
+    }
   else
     val |= (dwarf_version << 6);
-  
+
   if (optimize > 3)
     val |= (3 << 9);
   else
@@ -663,7 +679,7 @@ annobin_create_function_notes (void * gcc_data, void * user_data)
 
   if (! annobin_enable_static_notes)
     return;
-  
+
   if (asm_out_file == NULL)
     return;
 
@@ -716,7 +732,7 @@ annobin_create_function_notes (void * gcc_data, void * user_data)
        aname = aname_end = NULL;
     }
 #endif
-  
+
 #ifdef flag_cf_protection
   if (global_cf_option != flag_cf_protection)
     {
@@ -729,7 +745,7 @@ annobin_create_function_notes (void * gcc_data, void * user_data)
        aname = aname_end = NULL;
     }
 #endif
-  
+
   if (global_pic_option != compute_pic_option ())
     {
       annobin_inform (1, "Recording change in PIC status for %s", cname);
@@ -782,10 +798,14 @@ annobin_create_function_notes (void * gcc_data, void * user_data)
 
   if (annobin_note_count > count)
     {
-      // /* FIXME: This assumes that the function is in the .text section...  */
-      // fprintf (asm_out_file, "\t.pushsection .text\n");
+      /* This push/pop is probably not necssary, but let's be paranoid.  */
+      if (DECL_SECTION_NAME (current_function_decl) != NULL)
+       fprintf (asm_out_file, "\t.pushsection %s\n", DECL_SECTION_NAME (current_function_decl));
+
       fprintf (asm_out_file, "%s:\n", saved_aname_end);
-      // fprintf (asm_out_file, "\t.popsection\n");
+
+      if (DECL_SECTION_NAME (current_function_decl) != NULL)
+       fprintf (asm_out_file, "\t.popsection\n");
     }
 
   free ((void *) saved_aname_end);
@@ -933,7 +953,7 @@ annobin_create_global_notes (void * gcc_data, void * user_data)
 
   /* Record optimization level, -W setting and -g setting  */
   record_GOW_settings (global_GOWall_options, false, NULL, NULL, NULL);
-     
+
   /* Record -fstack-protector option.  */
   annobin_output_numeric_note (GNU_BUILD_ATTRIBUTE_STACK_PROT, global_stack_prot_option,
                               "numeric: -fstack-protector status",
@@ -960,7 +980,7 @@ annobin_create_global_notes (void * gcc_data, void * user_data)
        {
          if (save_decoded_options[i].arg == NULL)
            continue;
-           
+
          if (strncmp (save_decoded_options[i].arg, "_FORTIFY_SOURCE=", strlen ("_FORTIFY_SOURCE=")) == 0)
            {
              int level = atoi (save_decoded_options[i].arg + strlen ("_FORTIFY_SOURCE="));
@@ -1012,7 +1032,7 @@ annobin_create_global_notes (void * gcc_data, void * user_data)
 
   if (! glibcxx_assertions_recorded)
     record_glibcxx_assertions (false);
-  
+
   /* Record the PIC status.  */
   annobin_output_numeric_note (GNU_BUILD_ATTRIBUTE_PIC, global_pic_option,
                               "numeric: PIC", NULL, NULL, OPEN);
@@ -1051,7 +1071,7 @@ annobin_create_loader_notes (void * gcc_data, void * user_data)
     {
       annobin_inform (1, "Recording total static usage of %ld", annobin_total_static_stack_usage);
 
-      fprintf (asm_out_file, "\t.pushsection %s\n", GNU_BUILD_ATTRS_SECTION_NAME);    
+      fprintf (asm_out_file, "\t.pushsection %s\n", GNU_BUILD_ATTRS_SECTION_NAME);
       annobin_output_numeric_note (GNU_BUILD_ATTRIBUTE_STACK_SIZE, annobin_total_static_stack_usage,
                                   "numeric: stack-size", NULL, NULL, OPEN);
       fprintf (asm_out_file, "\t.popsection\n");
@@ -1088,6 +1108,9 @@ parse_args (unsigned argc, struct plugin_argument * argv)
       else if (strcmp (key, "verbose") == 0)
        verbose_level ++;
 
+      else if (strcmp (key, "function-verbose") == 0)
+       annobin_function_verbose = true;
+
       else if (strcmp (key, "global-file-syms") == 0)
        global_file_name_symbols = true;
       else if (strcmp (key, "no-global-file-syms") == 0)
@@ -1102,12 +1125,12 @@ parse_args (unsigned argc, struct plugin_argument * argv)
        annobin_enable_dynamic_notes = true;
       else if (strcmp (key, "no-dynamic-notes") == 0)
        annobin_enable_dynamic_notes = false;
-      
+
       else if (strcmp (key, "static-notes") == 0)
        annobin_enable_static_notes = true;
       else if (strcmp (key, "no-static-notes") == 0)
        annobin_enable_static_notes = false;
-      
+
       else if (strcmp (key, "stack-threshold") == 0)
        {
          stack_threshold = strtoul (argv[argc].value, NULL, 0);
index 669fa7df5173947d1dd8965de41b5ec67cfcd3d8..cb39860fbfb5d29583a663802df6887debcb0515 100644 (file)
@@ -29,7 +29,7 @@ annobin_record_global_target_notes (void)
     annobin_inform (0, "ICE: Should be 64-bit target");
 
   saved_tls_size = rs6000_tls_size;
-  
+
   annobin_output_numeric_note (GNU_BUILD_ATTRIBUTE_ABI, saved_tls_size,
                               "numeric: ABI: TLS size", NULL, NULL, OPEN);
   annobin_inform (1, "Recording global TLS size of %d", saved_tls_size);
index b3207fd3a44a6afa198b95a78d26230dc4083930..0245347466e41ba891ab9f11096093e27a5e74b9 100644 (file)
@@ -115,7 +115,7 @@ annobin_target_specific_function_notes (const char * aname, const char * aname_e
       if ((unsigned long) ix86_isa_flags > max_x86_isa)
        max_x86_isa = ix86_isa_flags;
     }
-  
+
 #ifdef flag_cet
   if (global_cet != flag_cet)
     fprintf (stderr, "1\n");
@@ -125,13 +125,13 @@ annobin_target_specific_function_notes (const char * aname, const char * aname_e
     fprintf (stderr, "3\n");
   if (global_shstk != (ix86_isa_flags & OPTION_MASK_ISA_SHSTK))
     fprintf (stderr, "4\n");
-      
+
   if ((global_cet != flag_cet)
       || (global_set_switch != flag_cet_switch)
       || (global_ibt != (ix86_isa_flags2 & OPTION_MASK_ISA_IBT))
       || (global_shstk != (ix86_isa_flags & OPTION_MASK_ISA_SHSTK)))
     {
-      annobin_inform (0, "CET values have changed from %d:%d:%lx:%lx to %d:%d:%lx:%lx",
+      annobin_inform (1, "CET values have changed from %d:%d:%lx:%lx to %d:%d:%lx:%lx",
                      global_cet, global_set_switch, global_ibt, global_shstk,
                      flag_cet, flag_cet_switch,
                      (ix86_isa_flags2 & OPTION_MASK_ISA_IBT),
@@ -218,7 +218,7 @@ annobin_target_specific_loader_notes (void)
   if (annobin_is_64bit)
     {
       Elf64_32_loader_note note32;
-      
+
       note32.pr_datasz = sizeof (note32.pr_data);
       note32.pr_pad = 0;
 
@@ -232,7 +232,7 @@ annobin_target_specific_loader_notes (void)
          memcpy (ptr, & note64, sizeof note64);
          ptr += sizeof (note64);
        }
-      
+
       note32.pr_type = GNU_PROPERTY_X86_ISA_1_USED;
       note32.pr_data = convert_gcc_isa_to_gnu_property_isa (max_x86_isa);
       memcpy (ptr, & note32, sizeof note32);
index 75086b0a0e9411a6a2104ec48cd7c64104a67327..081d49b66c0c613ca6c982db050478c9810156ab 100644 (file)
@@ -6,7 +6,7 @@
 
 ## Process this file with automake to produce Makefile.in.
 
-TESTS=compile-test hardening-test hardening-fail-test abi-test missing-notes-test
+TESTS=compile-test hardening-test hardening-fail-test abi-test missing-notes-test function-sections-test
 XFAIL_TESTS=hardening-fail-test
 
 # FIXME: Add a test for merging notes...
index 4504931f41d82fb4962a62ecdb0e661ddc7fac1f..2c9e0071e7679baa8ed91fe79d8614eac508d616 100644 (file)
@@ -211,7 +211,7 @@ target_vendor = @target_vendor@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
-TESTS = compile-test hardening-test hardening-fail-test abi-test missing-notes-test
+TESTS = compile-test hardening-test hardening-fail-test abi-test missing-notes-test function-sections-test
 XFAIL_TESTS = hardening-fail-test
 all: all-am
 
index b4211b5d0945b857038657ed0baf965b6b8f0f18..4b92b7a13710f4be0f2665dda5338d8b0e58643b 100644 (file)
@@ -2,6 +2,7 @@
 
 extern int big_stack (int);
 
+int ordinary_func (void) __attribute__((optimize("-O0"),__noinline__));
 int baz (void) __attribute__((optimize("-O0"),__noinline__));
 int bar (void) __attribute__((optimize("-fstack-protector-strong"),__noinline__));
 
This page took 0.046608 seconds and 5 git commands to generate.