1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
/* lkrel.c - .rel object file handling
Copyright (C) 1989-1995 Alan R. Baldwin
721 Berkeley St., Kent, Ohio 44240
Copyright (C) 2008-2010 Borut Razem, borut dot razem at siol dot net
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3, or (at your option) any
later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/*
* With contributions for the
* object libraries from
* Ken Hornstein
* kenh@cmf.nrl.navy.mil
*
*/
/*
* Extensions: P. Felber
*/
#include <assert.h>
#include "lk_readnl.h"
#include "aslink.h"
#include "lkrel.h"
int
is_rel (FILE * libfp)
{
int c;
long pos = ftell (libfp);
int ret = 0;
/* [XDQ][HL][234] */
if (((c = getc (libfp)) == 'X' || c == 'D' || c == 'Q') && ((c = getc (libfp)) == 'H' || c == 'L'))
{
switch (getc (libfp))
{
case '2':
case '3':
case '4':
switch (getc (libfp))
{
case '\r':
if (getc (libfp) == '\n')
ret = 1;
break;
case '\n':
ret = 1;
}
break;
case '\r':
if (getc (libfp) == '\n')
ret = 1;
break;
case '\n':
ret = 1;
}
}
else if (c == ';')
{
char buf[6];
if (fread (buf, 1, sizeof (buf), libfp) == sizeof (buf) && memcmp (buf, "!FILE ", 6) == 0)
ret = 1;
}
fseek (libfp, pos, SEEK_SET);
return ret;
}
/* Load a standalone or embedded .rel */
int
load_rel (FILE * libfp, long size)
{
if (is_rel (libfp))
{
char str[NINPUT];
long end;
end = (size >= 0) ? ftell (libfp) + size : -1;
while ((end < 0 || ftell (libfp) < end) && lk_readnl (str, sizeof (str), libfp) != NULL)
{
if (0 == strcmp (str, "</REL>"))
return 1;
ip = str;
link_main ();
}
return 1;
}
else
return 0;
}
int
enum_symbols (FILE * fp, long size, int (*func) (const char *symvoid, void *param), void *param)
{
char buf[NINPUT];
long end = (size >= 0) ? ftell (fp) + size : -1;
assert (func != NULL);
/*
* Read in the object file. Look for lines that
* begin with "S" and end with "D". These are
* symbol table definitions. If we find one, see
* if it is our symbol. Make sure we only read in
* our object file and don't go into the next one.
*/
while ((end < 0 || ftell (fp) < end) && lk_readnl (buf, sizeof (buf), fp) != NULL)
{
char symname[NINPUT];
char c;
/*
* When a 'T line' is found terminate file scan.
* All 'S line's preceed 'T line's in .REL files.
*/
if (buf[0] == 'T')
break;
/*
* Skip everything that's not a symbol record.
*/
if (buf[0] != 'S')
continue;
sscanf (buf, "S %s %c", symname, &c);
/* If it's an actual symbol, record it */
if (c == 'D')
{
if ((*func) (symname, param))
return 1;
}
}
return 0;
}
|