Bug 1860549 - annobin is broken on aarch64
Summary: annobin is broken on aarch64
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Fedora
Classification: Fedora
Component: annobin
Version: rawhide
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Nick Clifton
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2020-07-25 01:16 UTC by Elliott Sales de Andrade
Modified: 2020-08-13 07:54 UTC (History)
5 users (show)

Fixed In Version: annobin-9.24-2.fc33
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2020-07-26 09:38:19 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Elliott Sales de Andrade 2020-07-25 01:16:50 UTC
Description of problem:
annobin is broken due to gcc update, again.


Version-Release number of selected component (if applicable):
annobin                                aarch64  9.23-1.fc33


Steps to Reproduce:
1. Run a build that compiles on aarch64; see examples in additional info below.


Actual results:
gcc -I"/usr/include/R" -DNDEBUG -I./lib/  -I/usr/local/include  -fvisibility=hidden -fpic  -O2 -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -fasynchronous-unwind-tables -fstack-clash-protection  -c capture.c -o capture.o
annobin: capture.c: AArch64: The annobin plugin is out of date with respect to gcc
*** WARNING *** there are active plugins, do not report this as a bug unless you can reproduce it without enabling any plugins.
Event                            | Plugins
PLUGIN_FINISH_UNIT               | annobin: Generate final annotations
PLUGIN_START_UNIT                | annobin: Generate global annotations
PLUGIN_ALL_PASSES_START          | annobin: Generate per-function annotations
PLUGIN_ALL_PASSES_END            | annobin: Register per-function end symbol
capture.c:1: internal compiler error: Segmentation fault
    1 | #include <Rinternals.h>
      | 
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://bugzilla.redhat.com/bugzilla> for instructions.
Preprocessed source stored into /tmp/ccmLuyx1.out file, please attach this to your bugreport.


Expected results:
Builds work.


Additional info:
https://koji.fedoraproject.org/koji/taskinfo?taskID=47793792
https://koji.fedoraproject.org/koji/taskinfo?taskID=47794003

Comment 2 Nick Clifton 2020-07-26 07:33:46 UTC
Hi Elliot,

  This should now be fixed.  Please could you retry your build.

Cheers
  Nick

Comment 3 Elliott Sales de Andrade 2020-07-26 07:52:22 UTC
The version you have marked this as fixed in has not built.
https://koji.fedoraproject.org/koji/buildinfo?buildID=1546944

Comment 4 Nick Clifton 2020-07-26 08:53:58 UTC
True - the problem was harder than I thought.  I have checked in a new version (9-24-2) which should actually work this time.

Comment 5 Elliott Sales de Andrade 2020-07-26 09:38:19 UTC
OK, those packages I listed initially, plus some packages that require those (i.e., checking tests on the built results) are now working.

Comment 6 Jakub Jelinek 2020-08-12 13:01:09 UTC
Nick, in the light of the https://pagure.io/fesco/issue/2454 I had a look at annobin and I think
  /* Some flags are not stored in the global_options structure so we
     just have to return the flg var and hope that it is still valid.  */
  if (cl_option_index == OPT_flto)
    return flag_lto != NULL;
#ifdef flag_sanitize
  if (cl_option_index == OPT_fsanitize_)
    return flag_sanitize;
#endif
or even the flag_* macros used in the GCC macros the plugin uses just can't work reliably if
ever some option is added or removed.

So, what I'd like to propose is that at annobin configure time, annobin configure takes
gcc -print-file-name=plugin/include/options.h
and through sed, awk, python or whatever else creates a wrapper options.h that will #include_next the GCC options.h, and then
for each
^#define (.*) global_options.x_\1$
will append
#undef \1
#define \1 annobin_opt_remap (\1)
where
#define annobin_opt_remap(x) \
  (*({ \
       int annobin_idx = ((char *) &global_options.x_##x - (char *) &global_options); \
       gcc_assert (annobin_opt_remap_table[annobin_idx] != -1); \
       char *ptr; \
       __asm ("" : "=g" (ptr) : "0" (&global_options)); \
       ptr += annobin_opt_remap_table[annobin_idx]; \
       __typeof (global_options.x_##x) *res; \
       __asm ("" : "=g" (res) : "0" (ptr)); \
       res; }))
and furthermore, at annobin configure time compile a program that will remember the important information from cl_options array (I'd suggest opt_text and var_type fields and perhaps position in the cl_options array)
for entries with flag_var_offset different from (unsigned short) -1) and remember it indexed by flag_var_offset in some array it would generate.
Then, at annobin initialization time (as early as possible), populate the annobin_opt_remap_table array, by going through this array of stuff remembered from cl_options and compare that against what is in cl_options at runtime,
for anything that can't be remapped set it to -1 (I think one can use a short array for that), and for anything that can be remapped put there the right remapping index.
If annobin is rebuilt against the latest gcc or if no options have been added or removed, this remap table should contain identity in the table and perhaps it would be best to start verification
at the remembered cl_options array position and only if it doesn't match, look around (in most cases it should be a few entries earlier or later).

So then, if you just use flag_lto in annobin, or even if e.g. the POINTER_SIZE macro uses flag_whatever under the hood somewhere, it will actually access the right global_options offset.
by

Comment 7 Nick Clifton 2020-08-12 16:37:01 UTC
Hi Jakub,

  Gosh - that seems incredibly complex, and probably error prone.

  Wouldn't it be simpler to just prevent any access to the global_options
  array (in annobin) except via the annobin_remap() function ?  Ie could I
  use:

    #pragma GCC poison global_options
    #include "options.h"

  Then any use by annobin code will be flaged as an error and I can fix it.
  (If necessary annobin_remap can be defined in a separate file which does
  not use this pragma).

Cheers
  Nick

Comment 8 Jakub Jelinek 2020-08-13 07:54:22 UTC
I don't think it is that complex and it is certainly not error prone, it is a way to make sure it just works.
Anyway, you can certainly try #pragma GCC poison global_options and see what breaks.  I'd guess a lot, including the
if (cl_option_index == OPT_flto)
    return flag_lto != NULL;
  if (cl_option_index == OPT_fsanitize_)
    return flag_sanitize;
I've cited.  I don't see why flag_lto is needed, that can be found in cl_options under OPT_flto_.
It is true that flag_sanitize and several others can't be found in cl_options, because they are just
Variable
unsigned int flag_...;
and not really mentioned as Var() of some option.  I guess we should discuss in GCC if we want to make some change that will allow tracking even those.


Note You need to log in before you can comment on or make changes to this bug.