[PATCH] give names to symbol kinds in collect2

Top Page

Reply to this message
Author: Olivier Hainque
Date:  
To: gcc-patches
CC: hainque
Subject: [PATCH] give names to symbol kinds in collect2
Hello,

This patch is an suggestion to give names to the ctor/dtor "symbol
kind" constants used throughout collect2, improving readability.

This is a standalone and functionally neutral change, in preparation
of further updates back on the topic of eh-tables handling on AIX, as
a followup to the thread around

http://gcc.gnu.org/ml/gcc-patches/2008-07/msg01347.html

Bootstrapped and regression tested on both powerpc-ibm-aix5.3 and
x86_64-suse-linux.

Thanks in advance,

Olivier

2008-07-24 Olivier Hainque <hainque@???>

    * collect2.c (symkind): New enum.
    (is_ctor_dtor): Return symkind instead of int. Adjust
    prototype, code and head comment accordingly.
    (scan_prog_file): Use symkind names instead of bare integers.

Index: collect2.c
===================================================================
*** collect2.c    (revision 137349)
--- collect2.c    (working copy)
*************** static struct path_prefix *libpaths[3] =
*** 236,243 ****
                     &libpath_lib_dirs, NULL};
#endif

static void handler (int);
- static int is_ctor_dtor (const char *);
static char *find_a_file (struct path_prefix *, const char *);
static void add_prefix (struct path_prefix *, const char *);
static void prefix_from_env (const char *, struct path_prefix *);
--- 236,256 ----
                     &libpath_lib_dirs, NULL};
#endif

+ /* Special kinds of symbols that a name may denote. */
+
+ typedef enum {
+ SYM_REGULAR = 0, /* nothing special */
+
+ SYM_CTOR = 1, /* constructor */
+ SYM_DTOR = 2, /* destructor */
+ SYM_INIT = 3, /* shared object routine that calls all the ctors */
+ SYM_FINI = 4, /* shared object routine that calls all the dtors */
+ SYM_DWEH = 5 /* DWARF exception handling table */
+ } symkind;
+
+ static symkind is_ctor_dtor (const char *);
+
static void handler (int);
static char *find_a_file (struct path_prefix *, const char *);
static void add_prefix (struct path_prefix *, const char *);
static void prefix_from_env (const char *, struct path_prefix *);
*************** dump_file (const char *name, FILE *to)
*** 519,530 ****
fclose (stream);
}
?
! /* Decide whether the given symbol is: a constructor (1), a destructor
! (2), a routine in a shared object that calls all the constructors
! (3) or destructors (4), a DWARF exception-handling table (5), or
! nothing special (0). */

! static int
is_ctor_dtor (const char *s)
{
struct names { const char *const name; const int len; const int ret;
--- 532,540 ----
fclose (stream);
}
?
! /* Return the kind of symbol denoted by name S. */

! static symkind
is_ctor_dtor (const char *s)
{
struct names { const char *const name; const int len; const int ret;
*************** is_ctor_dtor (const char *s)
*** 536,562 ****

static const struct names special[] = {
#ifndef NO_DOLLAR_IN_LABEL
! { "GLOBAL__I$", sizeof ("GLOBAL__I$")-1, 1, 0 },
! { "GLOBAL__D$", sizeof ("GLOBAL__D$")-1, 2, 0 },
#else
#ifndef NO_DOT_IN_LABEL
! { "GLOBAL__I.", sizeof ("GLOBAL__I.")-1, 1, 0 },
! { "GLOBAL__D.", sizeof ("GLOBAL__D.")-1, 2, 0 },
#endif /* NO_DOT_IN_LABEL */
#endif /* NO_DOLLAR_IN_LABEL */
! { "GLOBAL__I_", sizeof ("GLOBAL__I_")-1, 1, 0 },
! { "GLOBAL__D_", sizeof ("GLOBAL__D_")-1, 2, 0 },
! { "GLOBAL__F_", sizeof ("GLOBAL__F_")-1, 5, 0 },
! { "GLOBAL__FI_", sizeof ("GLOBAL__FI_")-1, 3, 0 },
! { "GLOBAL__FD_", sizeof ("GLOBAL__FD_")-1, 4, 0 },
! { NULL, 0, 0, 0 }
};

while ((ch = *s) == '_')
++s;

if (s == orig_s)
! return 0;

for (p = &special[0]; p->len > 0; p++)
{
--- 546,572 ----

static const struct names special[] = {
#ifndef NO_DOLLAR_IN_LABEL
! { "GLOBAL__I$", sizeof ("GLOBAL__I$")-1, SYM_CTOR, 0 },
! { "GLOBAL__D$", sizeof ("GLOBAL__D$")-1, SYM_DTOR, 0 },
#else
#ifndef NO_DOT_IN_LABEL
! { "GLOBAL__I.", sizeof ("GLOBAL__I.")-1, SYM_CTOR, 0 },
! { "GLOBAL__D.", sizeof ("GLOBAL__D.")-1, SYM_DTOR, 0 },
#endif /* NO_DOT_IN_LABEL */
#endif /* NO_DOLLAR_IN_LABEL */
! { "GLOBAL__I_", sizeof ("GLOBAL__I_")-1, SYM_CTOR, 0 },
! { "GLOBAL__D_", sizeof ("GLOBAL__D_")-1, SYM_DTOR, 0 },
! { "GLOBAL__F_", sizeof ("GLOBAL__F_")-1, SYM_DWEH, 0 },
! { "GLOBAL__FI_", sizeof ("GLOBAL__FI_")-1, SYM_INIT, 0 },
! { "GLOBAL__FD_", sizeof ("GLOBAL__FD_")-1, SYM_FINI, 0 },
! { NULL, 0, SYM_REGULAR, 0 }
};

while ((ch = *s) == '_')
++s;

if (s == orig_s)
! return SYM_REGULAR;

for (p = &special[0]; p->len > 0; p++)
{
*************** is_ctor_dtor (const char *s)
*** 567,573 ****
     return p->ret;
    }
}
! return 0;
}
?
/* We maintain two prefix lists: one from COMPILER_PATH environment variable
--- 577,583 ----
     return p->ret;
    }
}
! return SYM_REGULAR;
}
?
/* We maintain two prefix lists: one from COMPILER_PATH environment variable
*************** scan_prog_file (const char *prog_name, e
*** 2171,2187 ****
*end = '\0';
switch (is_ctor_dtor (name))
    {
!     case 1:
     if (which_pass != PASS_LIB)
     add_to_list (&constructors, name);
     break;

!     case 2:
     if (which_pass != PASS_LIB)
     add_to_list (&destructors, name);
     break;

!     case 3:
     if (which_pass != PASS_LIB)
     fatal ("init function found in object %s", prog_name);
#ifndef LD_INIT_SWITCH
--- 2181,2197 ----
*end = '\0';
switch (is_ctor_dtor (name))
    {
!     case SYM_CTOR:
     if (which_pass != PASS_LIB)
     add_to_list (&constructors, name);
     break;

!     case SYM_DTOR:
     if (which_pass != PASS_LIB)
     add_to_list (&destructors, name);
     break;

!     case SYM_INIT:
     if (which_pass != PASS_LIB)
     fatal ("init function found in object %s", prog_name);
#ifndef LD_INIT_SWITCH
*************** scan_prog_file (const char *prog_name, e
*** 2189,2195 ****
#endif
     break;

!     case 4:
     if (which_pass != PASS_LIB)
     fatal ("fini function found in object %s", prog_name);
#ifndef LD_FINI_SWITCH
--- 2199,2205 ----
#endif
     break;

!     case SYM_FINI:
     if (which_pass != PASS_LIB)
     fatal ("fini function found in object %s", prog_name);
#ifndef LD_FINI_SWITCH
*************** scan_prog_file (const char *prog_name, e
*** 2197,2203 ****
#endif
     break;

!     case 5:
     if (which_pass != PASS_LIB)
     add_to_list (&frame_tables, name);
     break;
--- 2207,2213 ----
#endif
     break;

!     case SYM_DWEH:
     if (which_pass != PASS_LIB)
     add_to_list (&frame_tables, name);
     break;
*************** scan_prog_file (const char *prog_name, e
*** 2516,2522 ****

         switch (is_ctor_dtor (name))
            {
!             case 1:
             if (! is_shared)
             add_to_list (&constructors, name);
#if defined (COLLECT_EXPORT_LIST) && !defined (LD_INIT_SWITCH)
--- 2526,2532 ----

         switch (is_ctor_dtor (name))
            {
!             case SYM_CTOR:
             if (! is_shared)
             add_to_list (&constructors, name);
#if defined (COLLECT_EXPORT_LIST) && !defined (LD_INIT_SWITCH)
*************** scan_prog_file (const char *prog_name, e
*** 2525,2531 ****
#endif
             break;

!             case 2:
             if (! is_shared)
             add_to_list (&destructors, name);
#if defined (COLLECT_EXPORT_LIST) && !defined (LD_INIT_SWITCH)
--- 2535,2541 ----
#endif
             break;

!             case SYM_DTOR:
             if (! is_shared)
             add_to_list (&destructors, name);
#if defined (COLLECT_EXPORT_LIST) && !defined (LD_INIT_SWITCH)
*************** scan_prog_file (const char *prog_name, e
*** 2535,2548 ****
             break;

#ifdef COLLECT_EXPORT_LIST
!             case 3:
#ifndef LD_INIT_SWITCH
             if (is_shared)
             add_to_list (&constructors, name);
#endif
             break;

!             case 4:
#ifndef LD_INIT_SWITCH
             if (is_shared)
             add_to_list (&destructors, name);
--- 2545,2558 ----
             break;

#ifdef COLLECT_EXPORT_LIST
!             case SYM_INIT:
#ifndef LD_INIT_SWITCH
             if (is_shared)
             add_to_list (&constructors, name);
#endif
             break;

!             case SYM_FINI:
#ifndef LD_INIT_SWITCH
             if (is_shared)
             add_to_list (&destructors, name);
*************** scan_prog_file (const char *prog_name, e
*** 2550,2556 ****
             break;
#endif

!             case 5:
             if (! is_shared)
             add_to_list (&frame_tables, name);
#if defined (COLLECT_EXPORT_LIST) && !defined (LD_INIT_SWITCH)
--- 2560,2566 ----
             break;
#endif

!             case SYM_DWEH:
             if (! is_shared)
             add_to_list (&frame_tables, name);
#if defined (COLLECT_EXPORT_LIST) && !defined (LD_INIT_SWITCH)