本文整理汇总了C++中DataChunk::bind方法的典型用法代码示例。如果您正苦于以下问题:C++ DataChunk::bind方法的具体用法?C++ DataChunk::bind怎么用?C++ DataChunk::bind使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataChunk
的用法示例。
在下文中一共展示了DataChunk::bind方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ld_main
int ld_main(int argc, char **argv) {
bool showHelp, mustResolveRefs(true);
string outFileName("a.out.bin"), archString("8w32/32/8"), formatString("bin");
Size nObjects;
Addr binOffset(0);
/* Get command line arguments. */
CommandLineArgFlag fh("-h", "--help", "", showHelp);
CommandLineArgSetter<string>fa("-a", "--arch", "", archString);
CommandLineArgSetter<string>ff("-f", "--format", "", formatString);
CommandLineArgSetter<Addr> foffset("--offset", "", binOffset);
CommandLineArgSetter<string>fo("-o", "--output", "", outFileName);
int firstInput(0), newArgc;
for (size_t i = 0; i < argc; i++) {
if (*(argv[i]) != '-') { firstInput = i; newArgc = i; break; }
else if (string(argv[i]) == "--") { firstInput = i+1; newArgc = i; break; }
else i++; /* Skip both the switch and its argument. */
}
nObjects = argc - firstInput;
if (argc != 0) CommandLineArg::readArgs(newArgc, argv);
if (argc == 0 || showHelp) {
cout << Help::ldHelp;
exit(0);
}
if (firstInput == argc) {
cout << "Linker: no input files given.\n";
exit(1);
}
ArchDef arch(archString);
/* Read all of the objects, assign addresses to their chunks, and place them
in an address map.*/
vector<Obj *> objects(nObjects);
vector<DataChunk*> chunks;
map<string, Addr> gChunkMap;
Addr nextOffset(binOffset);
for (Size i = 0; i < nObjects; i++) {
map <string, Addr> lChunkMap;
/* Read the object. */
HOFReader hr(arch);
ifstream objFile(argv[firstInput + i]);
if (!objFile) {
cout << "Could not open \"" << argv[firstInput + i]
<< "\" for reading.\n";
exit(1);
}
objects[i] = hr.read(objFile);
/* Assign addresses to chunks. */
Obj &obj = *objects[i];
for (Size j = 0; j < obj.chunks.size(); j++) {
DataChunk *c = dynamic_cast<DataChunk*>(obj.chunks[j]);
if (c->alignment != 0 && nextOffset % c->alignment)
nextOffset += c->alignment - (nextOffset % c->alignment);
c->bind(nextOffset);
chunks.push_back(c);
if (obj.chunks[j]->name != "") {
if (c->isGlobal()) gChunkMap[c->name] = nextOffset;
else lChunkMap[c->name] = nextOffset;
}
nextOffset += (c->size);
}
/* Resolve local references. */
for (Size i = 0; i < obj.chunks.size(); i++) {
DataChunk *dc = dynamic_cast<DataChunk*>(obj.chunks[i]);
for (Size j = 0; j < dc->refs.size(); j++) {
Ref &ref = *(dc->refs[j]);
if (lChunkMap.find(dc->refs[j]->name) != lChunkMap.end()) {
dc->refs[j]->bind(lChunkMap[dc->refs[j]->name],
dc->address + dc->refs[j]->ibase);
}
}
}
}
/* Resolve references. */
for (Size i = 0; i < chunks.size(); i++) {
DataChunk *dc = chunks[i];
for (Size j = 0; j < dc->refs.size(); j++) {
Ref &ref = *(dc->refs[j]);
if (!ref.bound && (gChunkMap.find(ref.name) != gChunkMap.end())) {
ref.bind(gChunkMap[ref.name], dc->address + ref.ibase);
} else if (!ref.bound && mustResolveRefs) {
cout << "Undefined symbol: \"" << ref.name << "\"\n";
exit(1);
}
}
}
/* Write out the chunks. */
ofstream outFile(outFileName.c_str());
for (Size i = 0; i < chunks.size(); i++) {
//.........这里部分代码省略.........