From efff188861bd6d859ac954f6a01dbca9bd52919f Mon Sep 17 00:00:00 2001 From: Nick Clifton Date: Mon, 10 Jan 2022 12:02:15 +0000 Subject: [PATCH] Add fix for fortify test --- annobin.fortify-test.patch | 85 ++++++++++++++++++++++++++++++++++++++ annobin.spec | 2 +- 2 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 annobin.fortify-test.patch diff --git a/annobin.fortify-test.patch b/annobin.fortify-test.patch new file mode 100644 index 0000000..4d419ac --- /dev/null +++ b/annobin.fortify-test.patch @@ -0,0 +1,85 @@ +--- annobin.orig/tests/fortify-test 2022-01-10 09:50:07.005146672 +0000 ++++ annobin-10.45/tests/fortify-test 2022-01-10 10:23:56.827404265 +0000 +@@ -37,30 +37,37 @@ fi + # Now add in our newly built plugin. + OPTS+=" -fplugin=$PLUGIN" + ++# For debugging purposes, generate a linker map as well. ++OPTS+=" -Wl,-Map,fortify-test.map" ++ + start_test + +-$GCC $OPTS -Wp,-U_FORTIFY_SOURCE -fno-lto $srcdir/main.c -o main.exe ++# Use atexit.c rather than main.c as it is bigger. ++COMMAND="$GCC $OPTS -Wp,-U_FORTIFY_SOURCE -fno-lto $srcdir/atexit.c -o fortify-test.exe" ++$COMMAND + if [ $? != 0 ]; + then + echo " $TEST_NAME: FAIL: unable to compile test file" +- echo " $TEST_NAME: compile command: $GCC $OPTS -Wp,-U_FORTIFY_SOURCE -fno-lto $srcdir/main.c -o main.exe" ++ echo " $TEST_NAME: command: $COMMAND" + end_test + exit 1 + fi + + # Run annocheck + +-SKIPS="--skip-cf-protection --skip-property-note --skip-stack-realign --skip-entry --skip-dynamic-tags --skip-lto --skip-warnings --skip-dynamic-tags --skip-not-dynamic-tags --skip-branch-protection --skip-not-branch-protection" +-$ANNOCHECK main.exe $SKIPS > main.out +-grep -e "Overall: FAIL" main.out ++SKIPS="--skip-all --test-fortify" ++A_COMMAND="$ANNOCHECK fortify-test.exe $SKIPS" ++$A_COMMAND > fortify-test.out ++grep -e "Overall: FAIL" fortify-test.out + if [ $? != 0 ]; + then + echo " $TEST_NAME: FAIL: compiling with -D_FORTIFY_SOURCE=2 still produces an executable that passes annocheck" +- echo " $TEST_NAME: compile command: $GCC $OPTS -Wp,-U_FORTIFY_SOURCE -fno-lto $srcdir/main.c -o main.exe" +- echo " $TEST_NAME: annocheck command: $ANNOCHECK main.exe $SKIPS" ++ echo " $TEST_NAME: compile command: $COMMAND" ++ echo " $TEST_NAME: annocheck command: $A_COMMAND" + echo " $TEST_NAME: annocheck output (with verbose enabled):" +- $ANNOCHECK main.exe $SKIPS --verbose +- uuencode main.exe main.exe ++ $A_COMMAND --verbose ++ uuencode fortify-test.exe fortify-test.exe ++ uuencode fortify-test.map fortify-test.map + end_test + exit 1 + fi +--- annobin.orig/gcc-plugin/annobin.cc 2022-01-10 09:50:06.991146761 +0000 ++++ annobin-10.45/gcc-plugin/annobin.cc 2022-01-10 11:31:49.507826587 +0000 +@@ -1,5 +1,5 @@ + /* annobin - a gcc plugin for annotating binary files. +- Copyright (c) 2017 - 2021 Red Hat. ++ Copyright (c) 2017 - 2022 Red Hat. + Created by Nick Clifton. + + This is free software; you can redistribute it and/or modify it +@@ -2485,6 +2485,7 @@ annobin_emit_end_symbol (const char * su + fprintf (asm_out_file, "\t.size %s%s, 0\n", annobin_current_endname, suffix); + annobin_inform (INFORM_VERBOSE, "Create symbol %s%s", annobin_current_endname, suffix); + ++#if 0 + /* If there is a bias to the start symbol, we can end up with the case where + the start symbol is after the end symbol. (If the section is empty). + Catch that and adjust the start symbol. This also pacifies eu-elflint +@@ -2509,7 +2510,8 @@ annobin_emit_end_symbol (const char * su + annobin_current_endname, suffix); + fprintf (asm_out_file, "\t.endif\n"); + } +- ++#endif ++ + fprintf (asm_out_file, "\t.popsection\n"); + } + +@@ -2774,7 +2776,7 @@ plugin_init (struct plugin_name_args * + solution is needed. */ + annobin_attach_type = group; + #if GCCPLUGIN_VERSION_MAJOR >= 11 +- if (target_start_sym_bias == 0) ++ /* if (target_start_sym_bias == 0)*/ + annobin_attach_type = link_order; + #endif + } diff --git a/annobin.spec b/annobin.spec index b74c9dc..cc10abc 100644 --- a/annobin.spec +++ b/annobin.spec @@ -66,7 +66,7 @@ Source: https://nickc.fedorapeople.org/%{annobin_sources} %global annobin_source_dir %{_usrsrc}/annobin # Insert patches here, if needed. Eg: -# Patch01: annobin-foo.patch +Patch01: annobin.fortify-test.patch #---------------------------------------------------------------------------------