-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathlinker2.cpp
More file actions
585 lines (541 loc) · 26.7 KB
/
linker2.cpp
File metadata and controls
585 lines (541 loc) · 26.7 KB
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
/**************************** relink.cpp ***********************************
* Author: Agner Fog
* date created: 2017-12-07
* Last modified: 2018-03-30
* Version: 1.13
* Project: Binary tools for ForwardCom instruction set
* Description:
* This module contains the relinking feature of the linker.
*
* Copyright 2017-2024 GNU General Public License http://www.gnu.org/licenses
*****************************************************************************/
#include "stdafx.h"
// load executable file to be relinked
void CLinker::loadExeFile() {
// Read input file
const char * inputFileName = cmd.getFilename(cmd.inputFile);
inputFile.read(inputFileName);
if (err.number()) return;
inputFile.split();
if (!(inputFile.fileHeader.e_flags & EF_RELINKABLE)) {
err.submit(ERR_INPUT_NOT_RELINKABLE, inputFileName);
return;
}
// get names of modules and libraries to remove or replace
getReplaceNames();
#if 0
for (int i = 0; i < rnames.numEntries(); i++) {
printf("\n%4X %s", rnames[i].command, cmd.getFilename(rnames[i].filename));
}
#endif
markSectionsInInputFile();
}
// get names of modules and libraries to remove or replace
void CLinker::getReplaceNames() {
uint32_t i, j; // loop counter. command index
const char * fname; // file name or module name
SLCommand cmd2; // copy of command line item
numObjects = 0; // number of object files to add
numLibraries = 0; // number of library files to add
bool isLib; // file name indicates a library (.li or .a)
// make a list of removed and replaced modules and libraries
// and count number of object files and library files
for (i = 0; i < cmd.lcommands.numEntries(); i++) {
cmd2.command = 0;
// name of module
fname = cmd.getFilename(cmd.lcommands[i].filename);
// is it a library?
isLib = false;
// find last '.'
for (j = (int32_t)strlen(fname) - 1; j > 0; j--) {
if (fname[j] == '.') break;
}
if ((j > 0 && strncasecmp_(fname + j, ".li", 3) == 0) || fname[j+1] == 'a') {
isLib = true;
}
if ((cmd.lcommands[i].command & 0xFF) == CMDL_LINK_ADDMODULE) {
// remove path
cmd.lcommands[i].value = cmd.fileNameBuffer.pushString(removePath(fname));
if (isLib) { // this is a library
numLibraries++;
cmd.lcommands[i].command = CMDL_LINK_ADDLIBRARY | (cmd.lcommands[i].command & CMDL_LINK_RELINKABLE);
}
else { // assume that this is an object file
numObjects++;
}
cmd2 = cmd.lcommands[i];
cmd2.command |= CMDL_LINK_REPLACE;
}
if ((cmd.lcommands[i].command & 0xFF) == CMDL_LINK_ADDLIBMODULE) {
// object module from library file
// remove path
cmd.lcommands[i].value = cmd.fileNameBuffer.pushString(removePath(fname));
numObjects++;
cmd2 = cmd.lcommands[i];
cmd2.command |= CMDL_LINK_REPLACE;
}
if ((uint8_t)cmd.lcommands[i].command == CMDL_LINK_REMOVE) {
// remove module from relinkable file
// remove path
cmd.lcommands[i].value = cmd.fileNameBuffer.pushString(removePath(fname));
cmd2 = cmd.lcommands[i];
if (isLib) cmd2.command |= CMDL_LINK_ADDLIBRARY;
else cmd2.command |= CMDL_LINK_ADDMODULE;
}
// add command to rnames
if (cmd2.command) {
int32_t r = rnames.findFirst(cmd2);
if (r >= 0) {
// already in list. combine commands
rnames[r].command |= cmd2.command;
}
else {
// new name. add to list
rnames.addUnique(cmd2);
}
}
}
}
// check which sections to keep or remove in executable input file,
// and make list of modules and libraries to relink
void CLinker::markSectionsInInputFile() {
uint32_t sec; // section index
uint32_t rec; // rnames index
const char * modName; // module name
const char * libName; // library name
SLCommand cmdrec; // command record used only for name search
SRelinkModule relModul; // name of relinked module
zeroAllMembers(cmdrec);
for (sec = 0; sec < inputFile.sectionHeaders.numEntries(); sec++) {
ElfFwcShdr secHdr = inputFile.sectionHeaders[sec];
if (secHdr.sh_type == 0) continue;
inputFile.sectionHeaders[sec].sh_relink = 0;
if (secHdr.sh_module && secHdr.sh_module < inputFile.secStringTableLen) {
modName = inputFile.secStringTable + secHdr.sh_module;
}
else modName = "";
if (secHdr.sh_library && secHdr.sh_library < inputFile.secStringTableLen) {
libName = inputFile.secStringTable + secHdr.sh_library;
}
else libName = "";
// search for module name and library name in rnames
zeroAllMembers(cmdrec);
zeroAllMembers(relModul);
if (modName[0]) {
cmdrec.value = relModul.moduleName = cmd.fileNameBuffer.pushString(modName);
int32_t f1 = rnames.findFirst(cmdrec);
if (f1 >= 0) {
// module name is in list
rnames[f1].command |= CMD_NAME_FOUND; // mark name found
cmdrec.command = rnames[f1].command & ~CMDL_LINK_ADDLIBRARY;
if (inputFile.sectionHeaders[sec].sh_flags & SHF_RELINK) {
inputFile.sectionHeaders[sec].sh_relink = (uint8_t)rnames[f1].command; // mark section for replace or delete
}
else {
err.submit(ERR_CANT_RELINK_MODULE, modName);
}
}
}
if (libName[0]) {
cmdrec.value = relModul.libraryName = cmd.fileNameBuffer.pushString(libName);
int32_t f2 = rnames.findFirst(cmdrec);
if (f2 >= 0) {
// library name is in list
rnames[f2].command |= CMD_NAME_FOUND; // mark name found
cmdrec.command = rnames[f2].command | CMDL_LINK_ADDLIBRARY;
if (inputFile.sectionHeaders[sec].sh_flags & SHF_RELINK) {
inputFile.sectionHeaders[sec].sh_relink |= (uint8_t)rnames[f2].command; // mark section for replace or delete
}
else {
err.submit(ERR_CANT_RELINK_LIBRARY, modName);
}
}
}
// add module or library to relinkModules list unless it is removed or replaced
if (cmdrec.value && !(cmdrec.command & (CMDL_LINK_REMOVE | CMDL_LINK_REPLACE))) {
relinkModules.addUnique(relModul);
}
#if 0 // testing only: list sections
const char * secName; // section name
if (secHdr.sh_name < inputFile.stringBuffer.dataSize()) {
secName = inputFile.stringBuffer.getString(secHdr.sh_name);
}
else secName = "";
printf("\n: %2i >> %s %s %s %2X", sec, secName, libName, modName, inputFile.sectionHeaders[sec].sh_relink);
#endif
}
#if 0 // testing only: list kept modules and libraries
for (rec = 0; rec < relinkModules.numEntries(); rec++) {
printf("\n# %s:%s", cmd.getFilename(relinkModules[rec].libraryName), cmd.getFilename(relinkModules[rec].moduleName));
}
#endif
// check if all remove/replace records in rnames have been matched by sections in input file
for (rec = 0; rec < rnames.numEntries(); rec++) {
if ((rnames[rec].command & CMDL_LINK_REMOVE) && !(rnames[rec].command & CMD_NAME_FOUND)) {
// unmatched name
modName = cmd.getFilename(uint32_t(rnames[rec].value));
if (rnames[rec].command & CMDL_LINK_ADDMODULE) {
err.submit(ERR_RELINK_MODULE_NOT_FOUND, modName);
}
else {
err.submit(ERR_RELINK_LIBRARY_NOT_FOUND, modName);
}
}
}
}
// extract a module from executable input file
void CLinker::extractModule(CELF & modul, uint32_t libname, uint32_t name) {
// libname: library name as index into cmd.fileNameBuffer. Zero if not a library member
// name: module name as index into cmd.fileNameBuffer. Zero to build a module of all non-relinkable sections
uint32_t sec; // section index in inputFile
uint32_t seci; // section index in modul
uint32_t sym; // symbol index in inputFile
uint32_t symi; // symbol index in modul
uint32_t rel; // relocation index in inputFile
const char * modName; // module name of section
const char * libName; // library name of library
const char * modName1; // module name to search for
const char * libName1; // library name to search for
uint32_t * symp; // pointer to symbol index
modName1 = cmd.getFilename(name); // will be "" if name = 0
libName1 = cmd.getFilename(libname); // will be "" if libname = 0
CDynamicArray<uint32_t> symbolTranslate; // list for translating symbol indexes from inputFile to modul
CDynamicArray<uint32_t> sectionTranslate; // list for translating section indexes from inputFile to modul
CDynamicArray<SSymbol2> externalSymbols; // list of external symbols referenced by current module
CDynamicArray<uint32_t> symbolTranslate2; // list for translating symbol indexes from externalSymbols to modul
ElfFwcSym symrec; // symbol record
// prepare translation of symbol indexes
symbolTranslate.setNum(inputFile.symbols.numEntries());
sectionTranslate.setNum(inputFile.sectionHeaders.numEntries());
zeroAllMembers(symrec);
modul.addSymbol(symrec, inputFile.stringBuffer); // make symbol zero empty
// loop through sections of input file
for (sec = 0; sec < inputFile.sectionHeaders.numEntries(); sec++) {
ElfFwcShdr secHdr = inputFile.sectionHeaders[sec];
if (secHdr.sh_type == 0) continue; // skip first empty section
if (secHdr.sh_flags & SHF_RELINK) {
// relinkable section. check name match
if (secHdr.sh_module && secHdr.sh_module < inputFile.secStringTableLen) {
modName = inputFile.secStringTable + secHdr.sh_module;
}
else continue;
if (strcmp(modName, modName1) != 0) continue; // name doesn't match
// check library name
if (secHdr.sh_library && secHdr.sh_library < inputFile.secStringTableLen) {
libName = inputFile.secStringTable + secHdr.sh_library;
if (libname == 0) continue; // library member not requested
if (strcmp(libName, libName1) != 0) continue; // library name doesn't match
}
else if (libname) continue; // not a library member
}
else {
// non-relinkable section
if (name || libname) continue; // name = 0 for collecting non-relinkable sections
// non-relinkable sections must have fixed addresses relative to each other because the
// corresponding relocation records are not preserved.
// Insert address relative to ip_base, datap_base, or threadp_base:
switch (secHdr.sh_flags & SHF_BASEPOINTER) {
case SHF_IP:
secHdr.sh_addr = secHdr.sh_addr - inputFile.fileHeader.e_ip_base;
break;
case SHF_DATAP:
secHdr.sh_addr = secHdr.sh_addr - inputFile.fileHeader.e_datap_base;
break;
case SHF_THREADP:
secHdr.sh_addr = secHdr.sh_addr - inputFile.fileHeader.e_threadp_base;
break;
}
}
// all sections that do not match name and libname have been skipped now
if (secHdr.sh_flags & SHF_AUTOGEN) continue; // auto-generated section. will be re-made
// add this section to the module
seci = modul.addSection(secHdr, inputFile.stringBuffer, inputFile.dataBuffer);
sectionTranslate[sec] = seci;
// find symbols in this section
for (sym = 0; sym < inputFile.symbols.numEntries(); sym++) {
if (inputFile.symbols[sym].st_section == sec) {
// save symbol
symrec = inputFile.symbols[sym];
symrec.st_section = seci;
symi = modul.addSymbol(symrec, inputFile.stringBuffer);
symbolTranslate[sym] = symi;
}
}
}
// find relocations in any section belonging to this module
for (rel = 0; rel < inputFile.relocations.numEntries(); rel++) {
sec = inputFile.relocations[rel].r_section;
if (sec < sectionTranslate.numEntries()) {
seci = sectionTranslate[sec];
if (seci) {
ElfFwcReloc reloc = inputFile.relocations[rel];
reloc.r_section = seci;
// loop to cover both symbol and reference symbol in relocation record
for (int i = 0; i < 2; i++) {
symp = i ? &reloc.r_refsym : &reloc.r_sym;
if (*symp) {
// there is a symbol index
if (*symp < symbolTranslate.numEntries() && symbolTranslate[*symp]) {
// symbol is in same module. Translate to index in modul
*symp = symbolTranslate[*symp];
}
else if (*symp < inputFile.symbols.numEntries()) {
// symbol is external. make external symbol record
SSymbol2 symbol2 = inputFile.symbols[*symp];
symbol2.st_section = 0; // make symbol external
symbol2.st_value = 0;
// put symbol name in global symbolNameBuffer for the purpose of sorting
if (symbol2.st_name >= inputFile.stringBuffer.dataSize()) {
err.submit(ERR_ELF_INDEX_RANGE); return;
}
const char * symname = (char*)inputFile.stringBuffer.buf() + symbol2.st_name;
symbol2.st_name = symbolNameBuffer.pushString(symname);
// add to list of external symbols, avoid duplicates
externalSymbols.addUnique(symbol2);
// remember that symbol index is not resolved yet
*symp |= 0x80000000;
}
else err.submit(ERR_ELF_INDEX_RANGE);
}
}
// save relocation record
modul.addRelocation(reloc);
}
}
}
// add external symbols to modul and remember new indexes
symbolTranslate2.setNum(externalSymbols.numEntries());
for (sym = 0; sym < externalSymbols.numEntries(); sym++) {
symrec = externalSymbols[sym];
if (symrec.st_bind == STB_UNRESOLVED) {
symrec.st_bind = STB_GLOBAL; // unresolved symbol from incomplete executable. attempt to resolve it again
}
symbolTranslate2[sym] = modul.addSymbol(symrec, symbolNameBuffer);
}
// resolve external symbol indexes in relocation records in new module
for (rel = 0; rel < modul.relocations.numEntries(); rel++) {
ElfFwcReloc & modulReloc = modul.relocations[rel];
// loop to cover both symbol and reference symbol in relocation record
for (int i = 0; i < 2; i++) {
uint32_t * symp = i ? &modulReloc.r_refsym : &modulReloc.r_sym;
if (*symp & 0x80000000) {
// find symbol index in externalSymbols
SSymbol2 sym2 = inputFile.symbols[*symp & 0x7FFFFFFF];
const char * symname = (char*)inputFile.stringBuffer.buf() + sym2.st_name;
sym2.st_name = symbolNameBuffer.pushString(symname);
int32_t eindex = externalSymbols.findFirst(sym2);
if (eindex < 0) {
err.submit(ERR_INDEX_OUT_OF_RANGE); // should not occur
return;
}
*symp = symbolTranslate2[(uint32_t)eindex];
}
}
}
ElfFwcEhdr head;
zeroAllMembers(head);
modul.join(&head);
}
// count number of modules and libraries to reuse when relinking
void CLinker::countReusedModules() {
uint32_t rec; // record index
const char * libname; // library name
const char * lastlibname = ""; // library name of preceding record
numRelinkObjects = 1; // including modules1[0] which contains all reused non-relinkable modules
numRelinkLibraries = 0; // number of relinkable modules
// this is counted as one, even if unused
if (cmd.job != CMDL_JOB_RELINK) return; // not relinking
// loop through relinkModules list
for (rec = 0; rec < relinkModules.numEntries(); rec++) {
if (relinkModules[rec].libraryName) {
libname = cmd.getFilename(relinkModules[rec].libraryName);
if (rec > 0 && strcmp(libname, lastlibname) == 0) {
continue; // multiple modules from same library: count only once
}
lastlibname = libname;
numRelinkLibraries++;
}
else if (relinkModules[rec].moduleName) numRelinkObjects++;
}
}
// get all relinked objects into modules1 metabuffer
void CLinker::getRelinkObjects() {
uint32_t rec; // record index
uint32_t mod = 0; // module index
uint32_t sec = 0; // section index
const char * modname; // module name
// join all non-relinkable sections into first entry
extractModule(modules1[0], 0, 0);
mod++;
#if 1 // testing: write module file
modules1[0].write("ff.ob");
#endif
// mark all sections for fixed position because they have already been relocated
for (sec = 0; sec < modules1[0].sectionHeaders.numEntries(); sec++) {
modules1[0].sectionHeaders[sec].sh_flags |= SHF_FIXED;
}
if (cmd.verbose && numRelinkObjects > 1) {
printf("\nReusing object modules:");
}
// loop through relinkModules list to search for non-library modules
for (rec = 0; rec < relinkModules.numEntries(); rec++) {
if (relinkModules[rec].libraryName == 0 && relinkModules[rec].moduleName != 0) {
extractModule(modules1[mod], 0, relinkModules[rec].moduleName);
modules1[mod].moduleName = relinkModules[rec].moduleName;
modules1[mod].relinkable = true;
extractModuleToFile(modules1[mod]); // possibly extract to file
mod++;
// write name
if (cmd.verbose) {
modname = cmd.getFilename(relinkModules[rec].moduleName);
printf(" %s", modname);
}
}
}
}
// extract a module from relinkable file if requested
void CLinker::extractModuleToFile(CELF & modu) {
// search for extract command
if (!(cmd.libraryOptions & CMDL_LIBRARY_EXTRACTMEM)) return;
uint32_t i; // loop counter
const char * modname1; // module name
const char * modname2; // module name on command line
bool extract = false;
modname1 = cmd.getFilename(modu.moduleName);
if (modname1[0] == 0) return;
if (cmd.libraryOptions == CMDL_LIBRARY_EXTRACTALL) extract = true;
for (i = 0; i < cmd.lcommands.numEntries(); i++) {
if (cmd.lcommands[i].command == CMDL_LINK_EXTRACT) {
// name of module
modname2 = cmd.getFilename(cmd.lcommands[i].filename);
if (strcmp(modname1, modname2) == 0) {
extract = true;
break;
}
}
}
if (!extract) return; // no request for extracting this module
// make new name = old name prefixed by "x_"
uint32_t newname = cmd.fileNameBuffer.dataSize();
cmd.fileNameBuffer.push("x_", 2);
cmd.fileNameBuffer.pushString(modname1);
modname2 = cmd.getFilename(newname);
modu.write(modname2);
}
// recover relinkable library modules
void CLinker::getRelinkLibraries() {
if (cmd.job != CMDL_JOB_RELINK) return; // not relinking
uint32_t rec; // record index
const char * libname; // library name
const char * nextlibname = ""; // library name of next record
const char * modname; // module name
uint32_t iLibrary = numLibraries + 1; // library index
CELF modul; // recovered library module
if (cmd.verbose && numRelinkLibraries) {
printf("\nRecovering library modules:");
}
// loop through relinkModules list, looking for library modules
for (rec = 0; rec < relinkModules.numEntries(); rec++) {
if (relinkModules[rec].libraryName && relinkModules[rec].moduleName) {
libname = cmd.getFilename(relinkModules[rec].libraryName);
modname = cmd.getFilename(relinkModules[rec].moduleName);
if (cmd.verbose) {
printf(" %s:%s", libname, modname);
}
// extract library module from relinkable input file
modul.reset();
extractModule(modul, relinkModules[rec].libraryName, relinkModules[rec].moduleName);
modul.moduleName = relinkModules[rec].moduleName;
modul.library = iLibrary; //??
extractModuleToFile(modul); // extract to file if requested
// build internal library
libraries[iLibrary].addELF(modul);
if (rec + 1 < relinkModules.numEntries()) {
nextlibname = cmd.getFilename(relinkModules[rec+1].libraryName);
}
else nextlibname = "?/";
if (strcmp(libname, nextlibname) != 0) {
// last module for this library. Finish internal library
libraries[iLibrary].makeInternalLibrary();
libraries[iLibrary].libraryName = relinkModules[rec].libraryName;
libraries[iLibrary].relinkable = true;
iLibrary++;
}
}
}
}
// write feedback to console
void CLinker::feedBackText2() {
if (!(cmd.verbose)) return; // write feedback only if verbose
uint32_t i; // loop counter
const char * name; // name of file or module
const char * libname; // name of library
bool written = false; // message has been written
// search for removed objects
for (i = 0; i < rnames.numEntries(); i++) {
if (((uint8_t)rnames[i].command & CMDL_LINK_REMOVE) && !((uint8_t)rnames[i].command & CMDL_LINK_ADDLIBRARY)) {
if (!written) printf("\nRemoving object files:");
written = true;
name = cmd.getFilename(uint32_t(rnames[i].value));
printf(" %s", name);
if (!(rnames[i].command & CMD_NAME_FOUND)) printf(" failed!");
}
}
// list of added objects have already been written to console.
// write replaced and removed objects
written = false;
// search for replaced objects
for (i = 0; i < rnames.numEntries(); i++) {
if ((rnames[i].command & CMDL_LINK_ADDMODULE) && (rnames[i].command & CMD_NAME_FOUND)
&&!(rnames[i].command & CMDL_LINK_REMOVE)) {
if (!written) printf("\nReplacing object files:");
written = true;
name = cmd.getFilename(uint32_t(rnames[i].value));
printf(" %s", name);
}
}
written = false;
// search for removed libraries
for (i = 0; i < rnames.numEntries(); i++) {
if ((uint8_t)rnames[i].command == (CMDL_LINK_REMOVE | CMDL_LINK_ADDLIBRARY)) {
if (!written) printf("\nRemoving library files:");
written = true;
name = cmd.getFilename(rnames[i].filename);
printf(" %s", name);
if (!(rnames[i].command & CMD_NAME_FOUND)) printf(" failed!");
}
}
written = false;
// search for added libraries
for (i = 0; i < rnames.numEntries(); i++) {
if ((uint8_t)rnames[i].command == (CMDL_LINK_REPLACE | CMDL_LINK_ADDLIBRARY)
&& !(rnames[i].command & CMD_NAME_FOUND)) {
if (!written) printf("\nAdding library files:");
written = true;
name = cmd.getFilename(rnames[i].filename);
printf(" %s", name);
}
}
written = false;
// search for replaced libraries
for (i = 0; i < rnames.numEntries(); i++) {
if ((rnames[i].command & CMDL_LINK_REPLACE)
&& (rnames[i].command & CMDL_LINK_ADDLIBRARY)
&& (rnames[i].command & CMD_NAME_FOUND)) {
if (!written) printf("\nReplacing library files:");
written = true;
name = cmd.getFilename(rnames[i].filename);
printf(" %s", name);
}
}
written = false;
// search for added library members
for (i = 0; i < libmodules.numEntries(); i++) {
uint32_t lib = libmodules[i].library & 0x7FFFFFFF;
if (!written) printf("\nUsing library members:");
written = true;
libname = cmd.getFilename(libraries[lib].libraryName);
name = libraries[lib].getMemberName(libmodules[i].offset);
printf(" %s:%s", libname, name);
}
}