]> sourceware.org Git - glibc.git/commitdiff
Introduce link_map_audit_state accessor function
authorFlorian Weimer <fweimer@redhat.com>
Sat, 2 Nov 2019 19:04:02 +0000 (20:04 +0100)
committerFlorian Weimer <fweimer@redhat.com>
Fri, 15 Nov 2019 12:03:40 +0000 (13:03 +0100)
To improve GCC 10 compatibility, it is necessary to remove the l_audit
zero-length array from the end of struct link_map.  In preparation of
that, this commit introduces an accessor function for the audit state,
so that it is possible to change the representation of the audit state
without adjusting the code that accesses it.

Tested on x86_64-linux-gnu.  Built on i686-gnu.

Change-Id: Id815673c29950fc011ae5301d7cde12624f658df

csu/libc-start.c
elf/dl-close.c
elf/dl-fini.c
elf/dl-load.c
elf/dl-object.c
elf/dl-open.c
elf/dl-runtime.c
elf/dl-sym.c
elf/rtld.c
sysdeps/generic/ldsodefs.h

index 14e2b693f0bfa40b8f1d05aa8b6362a14c22135b..e9e8e44fe52aa272de8aca07c30177ac17c725f0 100644 (file)
@@ -272,7 +272,7 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL),
       for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt)
        {
          if (afct->preinit != NULL)
-           afct->preinit (&head->l_audit[cnt].cookie);
+           afct->preinit (&link_map_audit_state (head, cnt)->cookie);
 
          afct = afct->next;
        }
index de91c28f728d0c0f8c0895053803dc4d5a6045d4..c32e6473ad1f14bae61554e89094438d91340b89 100644 (file)
@@ -302,8 +302,12 @@ _dl_close_worker (struct link_map *map, bool force)
              for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt)
                {
                  if (afct->objclose != NULL)
-                   /* Return value is ignored.  */
-                   (void) afct->objclose (&imap->l_audit[cnt].cookie);
+                   {
+                     struct auditstate *state
+                       = link_map_audit_state (imap, cnt);
+                     /* Return value is ignored.  */
+                     (void) afct->objclose (&state->cookie);
+                   }
 
                  afct = afct->next;
                }
@@ -478,7 +482,10 @@ _dl_close_worker (struct link_map *map, bool force)
          for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt)
            {
              if (afct->activity != NULL)
-               afct->activity (&head->l_audit[cnt].cookie, LA_ACT_DELETE);
+               {
+                 struct auditstate *state = link_map_audit_state (head, cnt);
+                 afct->activity (&state->cookie, LA_ACT_DELETE);
+               }
 
              afct = afct->next;
            }
@@ -774,7 +781,10 @@ _dl_close_worker (struct link_map *map, bool force)
          for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt)
            {
              if (afct->activity != NULL)
-               afct->activity (&head->l_audit[cnt].cookie, LA_ACT_CONSISTENT);
+               {
+                 struct auditstate *state = link_map_audit_state (head, cnt);
+                 afct->activity (&state->cookie, LA_ACT_CONSISTENT);
+               }
 
              afct = afct->next;
            }
index bed736d756f93ca8b3832c99c56ba07c319a4d61..70e734630471bc35b4940b3b869b131048f87387 100644 (file)
@@ -152,9 +152,12 @@ _dl_fini (void)
                      for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt)
                        {
                          if (afct->objclose != NULL)
-                           /* Return value is ignored.  */
-                           (void) afct->objclose (&l->l_audit[cnt].cookie);
-
+                           {
+                             struct auditstate *state
+                               = link_map_audit_state (l, cnt);
+                             /* Return value is ignored.  */
+                             (void) afct->objclose (&state->cookie);
+                           }
                          afct = afct->next;
                        }
                    }
index c1bc8c26be1229fafc2a03afd9fb27edbcf8c3a8..6cdd11e6b0440a4123a404cc477053f7902910d6 100644 (file)
@@ -973,7 +973,8 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd,
              for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt)
                {
                  if (afct->activity != NULL)
-                   afct->activity (&head->l_audit[cnt].cookie, LA_ACT_ADD);
+                   afct->activity (&link_map_audit_state (head, cnt)->cookie,
+                                   LA_ACT_ADD);
 
                  afct = afct->next;
                }
@@ -1402,10 +1403,9 @@ cannot enable executable stack as shared object requires");
        {
          if (afct->objopen != NULL)
            {
-             l->l_audit[cnt].bindflags
-               = afct->objopen (l, nsid, &l->l_audit[cnt].cookie);
-
-             l->l_audit_any_plt |= l->l_audit[cnt].bindflags != 0;
+             struct auditstate *state = link_map_audit_state (l, cnt);
+             state->bindflags = afct->objopen (l, nsid, &state->cookie);
+             l->l_audit_any_plt |= state->bindflags != 0;
            }
 
          afct = afct->next;
@@ -1511,8 +1511,8 @@ open_verify (const char *name, int fd,
        {
          if (afct->objsearch != NULL)
            {
-             name = afct->objsearch (name, &loader->l_audit[cnt].cookie,
-                                     whatcode);
+             struct auditstate *state = link_map_audit_state (loader, cnt);
+             name = afct->objsearch (name, &state->cookie, whatcode);
              if (name == NULL)
                /* Ignore the path.  */
                return -1;
@@ -1970,8 +1970,8 @@ _dl_map_object (struct link_map *loader, const char *name,
          if (afct->objsearch != NULL)
            {
              const char *before = name;
-             name = afct->objsearch (name, &loader->l_audit[cnt].cookie,
-                                     LA_SER_ORIG);
+             struct auditstate *state = link_map_audit_state (loader, cnt);
+             name = afct->objsearch (name, &state->cookie, LA_SER_ORIG);
              if (name == NULL)
                {
                  /* Do not try anything further.  */
index 4dff99ed110201acc69df65b04d02cb43ba7fed4..225e2ccf8a019d6d137cc6afadd31af987d99982 100644 (file)
@@ -81,7 +81,7 @@ _dl_new_object (char *realname, const char *libname, int type,
   struct link_map *new;
   struct libname_list *newname;
 #ifdef SHARED
-  size_t audit_space = naudit * sizeof (new->l_audit[0]);
+  size_t audit_space = naudit * sizeof (struct auditstate);
 #else
 # define audit_space 0
 #endif
@@ -134,10 +134,8 @@ _dl_new_object (char *realname, const char *libname, int type,
 
 #ifdef SHARED
   for (unsigned int cnt = 0; cnt < naudit; ++cnt)
-    {
-      new->l_audit[cnt].cookie = (uintptr_t) new;
-      /* new->l_audit[cnt].bindflags = 0; */
-    }
+    /* No need to initialize bindflags due to calloc.  */
+    link_map_audit_state (new, cnt)->cookie = (uintptr_t) new;
 #endif
 
   /* new->l_global = 0;        We use calloc therefore not necessary.  */
index a9fd4cbceddc08ae8849a5ebebf72c5c1b255d4b..8d699d3ff8e7d85463e36a22a7168fe456f97b2f 100644 (file)
@@ -278,7 +278,10 @@ dl_open_worker (void *a)
          for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt)
            {
              if (afct->activity != NULL)
-               afct->activity (&head->l_audit[cnt].cookie, LA_ACT_CONSISTENT);
+               {
+                 struct auditstate *state = link_map_audit_state (head, cnt);
+                 afct->activity (&state->cookie, LA_ACT_CONSISTENT);
+               }
 
              afct = afct->next;
            }
index 342b794f541fee53c75b4f64dc5ff5830b8fa8c6..8457862ba7fef2692dd69e71fa74c61e5c1e9928 100644 (file)
@@ -325,15 +325,18 @@ _dl_profile_fixup (
                {
                  /* XXX Check whether both DSOs must request action or
                     only one */
-                 if ((l->l_audit[cnt].bindflags & LA_FLG_BINDFROM) != 0
-                     && (result->l_audit[cnt].bindflags & LA_FLG_BINDTO) != 0)
+                 struct auditstate *l_state = link_map_audit_state (l, cnt);
+                 struct auditstate *result_state
+                   = link_map_audit_state (result, cnt);
+                 if ((l_state->bindflags & LA_FLG_BINDFROM) != 0
+                     && (result_state->bindflags & LA_FLG_BINDTO) != 0)
                    {
                      if (afct->symbind != NULL)
                        {
                          uintptr_t new_value
                            = afct->symbind (&sym, reloc_result->boundndx,
-                                            &l->l_audit[cnt].cookie,
-                                            &result->l_audit[cnt].cookie,
+                                            &l_state->cookie,
+                                            &result_state->cookie,
                                             &flags,
                                             strtab2 + defsym->st_name);
                          if (new_value != (uintptr_t) sym.st_value)
@@ -421,10 +424,13 @@ _dl_profile_fixup (
                  & (LA_SYMB_NOPLTENTER << (2 * (cnt + 1)))) == 0)
            {
              long int new_framesize = -1;
+             struct auditstate *l_state = link_map_audit_state (l, cnt);
+             struct auditstate *bound_state
+               = link_map_audit_state (reloc_result->bound, cnt);
              uintptr_t new_value
                = afct->ARCH_LA_PLTENTER (&sym, reloc_result->boundndx,
-                                         &l->l_audit[cnt].cookie,
-                                         &reloc_result->bound->l_audit[cnt].cookie,
+                                         &l_state->cookie,
+                                         &bound_state->cookie,
                                          regs, &flags, symname,
                                          &new_framesize);
              if (new_value != (uintptr_t) sym.st_value)
@@ -504,9 +510,11 @@ _dl_call_pltexit (struct link_map *l, ElfW(Word) reloc_arg,
          && (reloc_result->enterexit
              & (LA_SYMB_NOPLTEXIT >> (2 * cnt))) == 0)
        {
+         struct auditstate *l_state = link_map_audit_state (l, cnt);
+         struct auditstate *bound_state
+           = link_map_audit_state (reloc_result->bound, cnt);
          afct->ARCH_LA_PLTEXIT (&sym, reloc_result->boundndx,
-                                &l->l_audit[cnt].cookie,
-                                &reloc_result->bound->l_audit[cnt].cookie,
+                                &l_state->cookie, &bound_state->cookie,
                                 inregs, outregs, symname);
        }
 
index 8209342b13686f35baac762d1e9144223b12a7c7..21e025bc42c03a2933588f8b8c6bb4c55636fe69 100644 (file)
@@ -198,17 +198,20 @@ RTLD_NEXT used in code not dynamically loaded"));
 
              for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt)
                {
+                 struct auditstate *match_audit
+                   = link_map_audit_state (match, cnt);
+                 struct auditstate *result_audit
+                   = link_map_audit_state (result, cnt);
                  if (afct->symbind != NULL
-                     && ((match->l_audit[cnt].bindflags & LA_FLG_BINDFROM)
-                         != 0
-                         || ((result->l_audit[cnt].bindflags & LA_FLG_BINDTO)
+                     && ((match_audit->bindflags & LA_FLG_BINDFROM) != 0
+                         || ((result_audit->bindflags & LA_FLG_BINDTO)
                              != 0)))
                    {
                      unsigned int flags = altvalue | LA_SYMB_DLSYM;
                      uintptr_t new_value
                        = afct->symbind (&sym, ndx,
-                                        &match->l_audit[cnt].cookie,
-                                        &result->l_audit[cnt].cookie,
+                                        &match_audit->cookie,
+                                        &result_audit->cookie,
                                         &flags, strtab + ref->st_name);
                      if (new_value != (uintptr_t) sym.st_value)
                        {
index d54a7965b4c1ab68320881262f22a9aba639a47a..e22c7560c993a19c4fe6898b9fbffc4616f6472d 100644 (file)
@@ -1025,9 +1025,9 @@ ERROR: audit interface '%s' requires version %d (maximum supported version %d);
   else
     *last_audit = (*last_audit)->next = &newp->ifaces;
 
-  /* The dynamic linker link map is statically allocated, initialize
-     the data now.  */
-  GL (dl_rtld_map).l_audit[GLRO (dl_naudit)].cookie
+  /* The dynamic linker link map is statically allocated, so the
+     cookie in _dl_new_object has not happened.  */
+  link_map_audit_state (&GL (dl_rtld_map), GLRO (dl_naudit))->cookie
     = (intptr_t) &GL (dl_rtld_map);
 
   ++GLRO(dl_naudit);
@@ -1046,9 +1046,9 @@ notify_audit_modules_of_loaded_object (struct link_map *map)
     {
       if (afct->objopen != NULL)
        {
-         map->l_audit[cnt].bindflags
-           = afct->objopen (map, LM_ID_BASE, &map->l_audit[cnt].cookie);
-         map->l_audit_any_plt |= map->l_audit[cnt].bindflags != 0;
+         struct auditstate *state = link_map_audit_state (map, cnt);
+         state->bindflags = afct->objopen (map, LM_ID_BASE, &state->cookie);
+         map->l_audit_any_plt |= state->bindflags != 0;
        }
 
       afct = afct->next;
@@ -1662,7 +1662,8 @@ ERROR: '%s': cannot process note segment.\n", _dl_argv[0]);
       for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt)
        {
          if (afct->activity != NULL)
-           afct->activity (&main_map->l_audit[cnt].cookie, LA_ACT_ADD);
+           afct->activity (&link_map_audit_state (main_map, cnt)->cookie,
+                           LA_ACT_ADD);
 
          afct = afct->next;
        }
@@ -2333,7 +2334,8 @@ ERROR: '%s': cannot process note segment.\n", _dl_argv[0]);
          for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt)
            {
              if (afct->activity != NULL)
-               afct->activity (&head->l_audit[cnt].cookie, LA_ACT_CONSISTENT);
+               afct->activity (&link_map_audit_state (head, cnt)->cookie,
+                               LA_ACT_CONSISTENT);
 
              afct = afct->next;
            }
index a6991f3ac77e9253037c4f2d6465612734420da3..923bd4cf363b7f28ea91bdf63ca8e99f26725a04 100644 (file)
@@ -1174,7 +1174,13 @@ rtld_active (void)
      initialized and active ld.so copy.  */
   return GLRO(dl_init_all_dirs) != NULL;
 }
-#endif
+
+static inline struct auditstate *
+link_map_audit_state (struct link_map *l, size_t index)
+{
+  return &l->l_audit[index];
+}
+#endif /* SHARED */
 
 __END_DECLS
 
This page took 0.067134 seconds and 5 git commands to generate.