1 /*****************************************************************************/
5 /* Duplicate export checking for the ar65 archiver */
9 /* (C) 1998 Ullrich von Bassewitz */
11 /* D-70597 Stuttgart */
12 /* EMail: uz@musoftware.de */
15 /* This software is provided 'as-is', without any expressed or implied */
16 /* warranty. In no event will the authors be held liable for any damages */
17 /* arising from the use of this software. */
19 /* Permission is granted to anyone to use this software for any purpose, */
20 /* including commercial applications, and to alter it and redistribute it */
21 /* freely, subject to the following restrictions: */
23 /* 1. The origin of this software must not be misrepresented; you must not */
24 /* claim that you wrote the original software. If you use this software */
25 /* in a product, an acknowledgment in the product documentation would be */
26 /* appreciated but is not required. */
27 /* 2. Altered source versions must be plainly marked as such, and must not */
28 /* be misrepresented as being the original software. */
29 /* 3. This notice may not be removed or altered from any source */
32 /*****************************************************************************/
38 #include "../common/hashstr.h"
47 /*****************************************************************************/
49 /*****************************************************************************/
53 /* A hash table entry */
54 typedef struct HashEntry_ HashEntry;
56 HashEntry* Next; /* Next in list */
57 unsigned Module; /* Module index */
58 char Name [1]; /* Name of identifier */
62 #define HASHTAB_SIZE 4783
63 static HashEntry* HashTab [HASHTAB_SIZE];
67 /*****************************************************************************/
69 /*****************************************************************************/
73 static HashEntry* NewHashEntry (const char* Name, unsigned Module)
74 /* Create and return a new hash entry */
76 /* Get the length of the name */
77 unsigned Len = strlen (Name);
79 /* Get memory for the struct */
80 HashEntry* H = Xmalloc (sizeof (HashEntry) + Len);
82 /* Initialize the fields and return it */
85 memcpy (H->Name, Name, Len);
92 void ExpInsert (const char* Name, unsigned Module)
93 /* Insert an exported identifier and check if it's already in the list */
97 /* Create a hash value for the given name */
98 unsigned HashVal = HashStr (Name) % HASHTAB_SIZE;
100 /* Create a new hash entry */
101 HashEntry* H = NewHashEntry (Name, Module);
103 /* Search through the list in that slot and print matching duplicates */
104 if (HashTab [HashVal] == 0) {
105 /* The slot is empty */
106 HashTab [HashVal] = H;
109 L = HashTab [HashVal];
111 if (strcmp (L->Name, Name) == 0) {
112 /* Duplicate entry */
113 Warning ("External symbol `%s' in module `%s' is duplicated in "
115 Name, GetObjName (L->Module), GetObjName (Module));
128 int ExpFind (const char* Name)
129 /* Check for an identifier in the list. Return -1 if not found, otherwise
130 * return the number of the module, that exports the identifer.
133 /* Get a pointer to the list with the symbols hash value */
134 HashEntry* L = HashTab [HashStr (Name) % HASHTAB_SIZE];
136 /* Search through the list in that slot */
137 if (strcmp (L->Name, Name) == 0) {