1 /*****************************************************************************/
5 /* Duplicate export checking for the ar65 archiver */
9 /* (C) 1998-2012, Ullrich von Bassewitz */
10 /* Roemerstrasse 52 */
11 /* D-70794 Filderstadt */
12 /* EMail: uz@cc65.org */
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 /*****************************************************************************/
50 /*****************************************************************************/
52 /*****************************************************************************/
56 /* A hash table entry */
57 typedef struct HashEntry HashEntry;
59 HashEntry* Next; /* Next in list */
60 const ObjData* Module; /* Pointer to object module */
61 char Name [1]; /* Name of identifier */
65 #define HASHTAB_SIZE 4783
66 static HashEntry* HashTab [HASHTAB_SIZE];
70 /*****************************************************************************/
72 /*****************************************************************************/
76 static HashEntry* NewHashEntry (const char* Name, const ObjData* Module)
77 /* Create and return a new hash entry */
79 /* Get the length of the name */
80 unsigned Len = strlen (Name);
82 /* Get memory for the struct */
83 HashEntry* H = xmalloc (sizeof (HashEntry) + Len);
85 /* Initialize the fields and return it */
88 memcpy (H->Name, Name, Len);
95 void ExpInsert (const char* Name, const ObjData* Module)
96 /* Insert an exported identifier and check if it's already in the list */
100 /* Create a hash value for the given name */
101 unsigned HashVal = HashStr (Name) % HASHTAB_SIZE;
103 /* Create a new hash entry */
104 HashEntry* H = NewHashEntry (Name, Module);
106 /* Search through the list in that slot and print matching duplicates */
107 if (HashTab [HashVal] == 0) {
108 /* The slot is empty */
109 HashTab [HashVal] = H;
112 L = HashTab [HashVal];
114 if (strcmp (L->Name, Name) == 0) {
115 /* Duplicate entry */
116 Warning ("External symbol '%s' in module '%s', library '%s', "
117 "is duplicated in module '%s'",
118 Name, L->Module->Name, LibName, Module->Name);
131 const ObjData* ExpFind (const char* Name)
132 /* Check for an identifier in the list. Return NULL if not found, otherwise
133 ** return a pointer to the module, that exports the identifer.
136 /* Get a pointer to the list with the symbols hash value */
137 HashEntry* L = HashTab [HashStr (Name) % HASHTAB_SIZE];
139 /* Search through the list in that slot */
140 if (strcmp (L->Name, Name) == 0) {