• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Return section type name.
2    Copyright (C) 2001, 2002 Red Hat, Inc.
3    Written by Ulrich Drepper <drepper@redhat.com>, 2001.
4 
5    This program is Open Source software; you can redistribute it and/or
6    modify it under the terms of the Open Software License version 1.0 as
7    published by the Open Source Initiative.
8 
9    You should have received a copy of the Open Software License along
10    with this program; if not, you may obtain a copy of the Open Software
11    License version 1.0 from http://www.opensource.org/licenses/osl.php or
12    by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
13    3001 King Ranch Road, Ukiah, CA 95482.   */
14 
15 #ifdef HAVE_CONFIG_H
16 # include <config.h>
17 #endif
18 
19 #include <stdio.h>
20 #include <libeblP.h>
21 
22 
23 const char *
ebl_section_type_name(ebl,section,buf,len)24 ebl_section_type_name (ebl, section, buf, len)
25      Ebl *ebl;
26      int section;
27      char *buf;
28      size_t len;
29 {
30   const char *res = ebl->section_type_name (section, buf, len);
31 
32   if (res == NULL)
33     {
34       static const char *knowntypes[] =
35 	{
36 #define KNOWNSTYPE(name) [SHT_##name] = #name
37 	  KNOWNSTYPE (NULL),
38 	  KNOWNSTYPE (PROGBITS),
39 	  KNOWNSTYPE (SYMTAB),
40 	  KNOWNSTYPE (STRTAB),
41 	  KNOWNSTYPE (RELA),
42 	  KNOWNSTYPE (HASH),
43 	  KNOWNSTYPE (DYNAMIC),
44 	  KNOWNSTYPE (NOTE),
45 	  KNOWNSTYPE (NOBITS),
46 	  KNOWNSTYPE (REL),
47 	  KNOWNSTYPE (SHLIB),
48 	  KNOWNSTYPE (DYNSYM),
49 	  KNOWNSTYPE (INIT_ARRAY),
50 	  KNOWNSTYPE (FINI_ARRAY),
51 	  KNOWNSTYPE (PREINIT_ARRAY),
52 	  KNOWNSTYPE (GROUP),
53 	  KNOWNSTYPE (SYMTAB_SHNDX)
54 	};
55 
56       /* Handle standard names.  */
57       if ((size_t) section < sizeof (knowntypes) / sizeof (knowntypes[0])
58 	  && knowntypes[section] != NULL)
59 	res = knowntypes[section];
60       /* The symbol versioning/Sun extensions.  */
61       else if (section >= SHT_LOSUNW && section <= SHT_HISUNW)
62 	{
63 	  static const char *sunwtypes[] =
64 	    {
65 #undef KNOWNSTYPE
66 #define KNOWNSTYPE(name) [SHT_##name - SHT_LOSUNW] = #name
67 	      KNOWNSTYPE (SUNW_move),
68 	      KNOWNSTYPE (SUNW_COMDAT),
69 	      KNOWNSTYPE (SUNW_syminfo),
70 	      KNOWNSTYPE (GNU_verdef),
71 	      KNOWNSTYPE (GNU_verneed),
72 	      KNOWNSTYPE (GNU_versym)
73 	    };
74 	  res = sunwtypes[section - SHT_LOSUNW];
75 	}
76       else
77 	{
78 	  /* A few GNU additions.  */
79 	  if (section == SHT_CHECKSUM)
80 	    res = "CHECKSUM";
81 	  else if (section == SHT_GNU_LIBLIST)
82 	    res = "GNU_LIBLIST";
83 	  /* Handle OS-specific section names.  */
84 	  else
85 	    {
86 	      if (section >= SHT_LOOS && section <= SHT_HIOS)
87 		snprintf (buf, len, "SHT_LOOS+%x", section - SHT_LOOS);
88 	      /* Handle processor-specific section names.  */
89 	      else if (section >= SHT_LOPROC && section <= SHT_HIPROC)
90 		snprintf (buf, len, "SHT_LOPROC+%x", section - SHT_LOPROC);
91 	      else if ((unsigned int) section >= SHT_LOUSER
92 		       && (unsigned int) section <= SHT_HIUSER)
93 		snprintf (buf, len, "SHT_LOUSER+%x", section - SHT_LOUSER);
94 	      else
95 		snprintf (buf, len, "%s: %d", gettext ("<unknown>"), section);
96 
97 	      res = buf;
98 	    }
99 	}
100     }
101 
102   return res;
103 }
104