-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdriver.d
56 lines (49 loc) · 1.54 KB
/
driver.d
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
import std.exception;
import std.stdio;
import relocation;
import sectiontable;
import segment;
import symboltable;
import workqueue;
import objectfile;
import linker;
import paths;
import datafile;
WorkQueue!ObjectFile loadObjects(string[] objFilenames, Paths paths, SymbolTable symtab, SectionTable sectab)
{
auto queue = new WorkQueue!string();
foreach(filename; objFilenames)
queue.append(filename);
auto objects = new WorkQueue!ObjectFile();
while (!queue.empty())
{
auto filename = queue.pop();
if (!paths.search(filename))
writeln("Warning - File not found: " ~ filename);
else
{
auto object = ObjectFile.detectFormat(new DataFile(filename));
enforce(object, "Unknown object file format: " ~ filename);
object.loadSymbols(symtab, sectab, queue, objects);
}
}
return objects;
}
void finalizeLoad(SymbolTable symtab, SectionTable sectab)
{
symtab.defineImports(sectab);
symtab.allocateComdef(sectab);
symtab.defineSpecial(sectab, imageBase);
symtab.checkUnresolved();
}
Segment[SegmentType] generateSegments(WorkQueue!ObjectFile objects, SymbolTable symtab, SectionTable sectab)
{
auto segments = sectab.allocateSegments(imageBase, segAlign, fileAlign);
symtab.buildImports(segments[SegmentType.Import].data, imageBase);
while (!objects.empty())
{
auto object = objects.pop();
object.loadData((SegmentType.TLS in segments) ? segments[SegmentType.TLS].base : -1);
}
return segments;
}