3 Copyright (C) 1989-1995 Alan R. Baldwin
4 721 Berkeley St., Kent, Ohio 44240
5 Copyright (C) 2008-2009 Borut Razem, borut dot razem at siol dot net
7 This program is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3, or (at your option) any
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 * With contributions for the
22 * object libraries from
24 * kenh@cmf.nrl.navy.mil
29 * Extensions: P. Felber
35 #include "lk_readnl.h"
47 /* buildlibraryindex - build an in-memory cache of the symbols contained in
51 buildlibraryindex_lib (struct lbname
*lbnh
, FILE * libfp
, pmlibraryfile This
, int type
)
55 while (lk_readnl (relfil
, sizeof (relfil
), libfp
) != NULL
)
60 if (lbnh
->path
!= NULL
)
62 strcpy (str
, lbnh
->path
);
64 if ((*str
!= '\0') && (str
[strlen (str
) - 1] != '/') && (str
[strlen (str
) - 1] != LKDIRSEP
))
66 strcat (str
, LKDIRSEPSTR
);
73 if ((relfil
[0] == '/') || (relfil
[0] == LKDIRSEP
))
75 strcat (str
, relfil
+ 1);
82 if (strchr (relfil
, FSEPX
) == NULL
)
84 sprintf (&str
[strlen (str
)], "%c%s", FSEPX
, LKOBJEXT
);
87 if ((fp
= fopen (str
, "rb")) != NULL
)
89 /* Opened OK - create a new libraryfile object for it */
92 libr
= This
= (pmlibraryfile
) new (sizeof (mlibraryfile
));
96 This
->next
= (pmlibraryfile
) new (sizeof (mlibraryfile
));
101 This
->libspc
= lbnh
->libspc
;
102 This
->relfil
= strdup (relfil
);
103 This
->filspc
= strdup (str
);
106 /* Start a new linked list of symbols for this module: */
107 This
->symbols
= NULL
;
109 add_rel_index (fp
, -1, This
);
111 } /* Closes if object file opened OK */
114 fprintf (stderr
, "?ASlink-Warning-Cannot open library module %s\n", str
);
116 } /* Ends while - processing all in libr */
124 fndsym_lib (const char *name
, struct lbname
*lbnh
, FILE * libfp
, int type
)
128 D ("Searching symbol: %s\n", name
);
130 while (lk_readnl (relfil
, sizeof (relfil
), libfp
) != NULL
)
135 if (lbnh
->path
!= NULL
)
137 strcpy (str
, lbnh
->path
);
139 if ((*str
!= '\0') && (str
[strlen (str
) - 1] != '/') && (str
[strlen (str
) - 1] != LKDIRSEP
))
141 strcat (str
, LKDIRSEPSTR
);
148 if ((relfil
[0] == '/') || (relfil
[0] == LKDIRSEP
))
150 strcat (str
, relfil
+ 1);
154 strcat (str
, relfil
);
157 if (strchr (relfil
, FSEPX
) == NULL
)
159 sprintf (&str
[strlen (str
)], "%c%s", FSEPX
, LKOBJEXT
);
162 if ((fp
= fopen (str
, "rb")) != NULL
)
164 /* Opened OK - create a new libraryfile object for it */
165 int ret
= add_rel_file (name
, lbnh
, relfil
, str
, -1, fp
, -1, type
);
169 D ("Loaded module %s from file %s.\n", str
, str
);
170 /* if cdb information required & adb file present */
173 FILE *xfp
= afile (str
, "adb", 0); //JCF: Nov 30, 2002
176 SaveLinkedFilePath (str
);
181 return 1; /* Found the symbol, so success! */
183 } /* Closes if object file opened OK */
186 fprintf (stderr
, "?ASlink-Warning-Cannot open library module %s\n", str
);
188 } /* Ends while - processing all in libr */
190 return 0; /* The symbol is not in this library */
194 /*)Function VOID loadfile_lib(filspc)
196 * char *filspc library object file specification
198 * The function loadfile() links the library object module.
201 * FILE *fp file handle
202 * int i input line length
203 * char str[] file input line
206 * char *ip pointer to linker input string
209 * int fclose() c_library
210 * char *lk_readnl() lk_readnl.c
211 * FILE * fopen() c_library
212 * VOID link_main() lkmain.c
213 * int strlen() c_library
216 * If file exists it is linked.
220 loadfile_lib (struct lbfile
*lbfh
)
223 fp
= fopen (lbfh
->filspc
, "rb");
231 fprintf (stderr
, "?ASlink-Error-Opening library '%s'\n", lbfh
->filspc
);
237 struct aslib_target aslib_target_lib
= {
240 &buildlibraryindex_lib
,