mirror of
https://github.com/ksherlock/merlin-utils.git
synced 2025-08-15 22:27:19 +00:00
misc fixes.
This commit is contained in:
31
link.cpp
31
link.cpp
@@ -74,6 +74,8 @@ symbol *find_symbol(const std::string &name) {
|
|||||||
struct cookie {
|
struct cookie {
|
||||||
std::string file;
|
std::string file;
|
||||||
std::vector<unsigned> remap;
|
std::vector<unsigned> remap;
|
||||||
|
//std::vector<std::pair<unsigned, unsigned>> zero;
|
||||||
|
|
||||||
uint32_t start = 0;
|
uint32_t start = 0;
|
||||||
uint32_t length = 0;
|
uint32_t length = 0;
|
||||||
};
|
};
|
||||||
@@ -162,25 +164,25 @@ void process_reloc(byte_view &data, cookie &cookie) {
|
|||||||
external = flag & 0x04;
|
external = flag & 0x04;
|
||||||
switch(flag & ~0x04) {
|
switch(flag & ~0x04) {
|
||||||
case 0xd0:
|
case 0xd0:
|
||||||
shift = 16;
|
shift = -16;
|
||||||
size = 1;
|
size = 1;
|
||||||
break;
|
break;
|
||||||
case 0xd1:
|
case 0xd1:
|
||||||
shift = 8;
|
shift = -8;
|
||||||
size = 2;
|
size = 2;
|
||||||
break;
|
break;
|
||||||
case 0xd3:
|
case 0xd3:
|
||||||
shift = 8;
|
shift = -8;
|
||||||
size = 1;
|
size = 1;
|
||||||
break;
|
break;
|
||||||
default: /* bad */
|
default: /* bad */
|
||||||
errx(1, "%s: Unsupported flag: %02x\n", cookie.file.c_str(), flag);
|
errx(1, "%s: Unsupported flag: %02x\n", cookie.file.c_str(), flag);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
data.remove_prefix(4);
|
||||||
} else {
|
} else {
|
||||||
assert((flag & ~(0x0f|0x10|0x20|0x80)) == 0);
|
assert((flag & ~(0x0f|0x10|0x20|0x80)) == 0);
|
||||||
|
|
||||||
unsigned size = 0;
|
|
||||||
switch(flag & (0x80 + 0x20)) {
|
switch(flag & (0x80 + 0x20)) {
|
||||||
case 0:
|
case 0:
|
||||||
size = 1;
|
size = 1;
|
||||||
@@ -230,13 +232,17 @@ void process_reloc(byte_view &data, cookie &cookie) {
|
|||||||
uint32_t value = 0;
|
uint32_t value = 0;
|
||||||
omf::reloc r;
|
omf::reloc r;
|
||||||
r.size = size;
|
r.size = size;
|
||||||
r.offset = cookie.start; /* ???? */
|
r.offset = offset; /* ???? */
|
||||||
r.value = value;
|
r.value = value;
|
||||||
r.shift = shift;
|
r.shift = shift;
|
||||||
|
|
||||||
seg.relocs.emplace_back(r);
|
seg.relocs.emplace_back(r);
|
||||||
}
|
}
|
||||||
|
/* clear out the inline relocation data */
|
||||||
|
for(unsigned i = 0; i < size; ++i) {
|
||||||
|
seg.data[offset + i] = 0;
|
||||||
|
}
|
||||||
|
//cookie.zero.emplace_back(std::make_pair(offset, size));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -284,23 +290,24 @@ void process_unit(const std::string &path) {
|
|||||||
errx(1, "Invalid aux type %s", path.c_str());
|
errx(1, "Invalid aux type %s", path.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
omf::segment &seg = segments.back();
|
omf::segment &seg = segments.back();
|
||||||
|
|
||||||
seg.data.insert(seg.data.end(), mf.data(), mf.data() + offset);
|
|
||||||
|
|
||||||
byte_view data(mf.data() + offset, mf.size() - offset);
|
|
||||||
|
|
||||||
cookie.start = seg.data.size();
|
cookie.start = seg.data.size();
|
||||||
cookie.length = offset;
|
cookie.length = offset;
|
||||||
cookie.file = path;
|
cookie.file = path;
|
||||||
|
|
||||||
|
seg.data.insert(seg.data.end(), mf.data(), mf.data() + offset);
|
||||||
|
byte_view data(mf.data() + offset, mf.size() - offset);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
byte_view rr = data;
|
byte_view rr = data;
|
||||||
/* skip over the relocation records so we can process the labels first. */
|
/* skip over the relocation records so we can process the labels first. */
|
||||||
/* this is so external references can use the global symbol id */
|
/* this is so external references can use the global symbol id */
|
||||||
|
assert(data.size() >= 2);
|
||||||
for(;;) {
|
for(;;) {
|
||||||
assert(data.size() >= 6);
|
|
||||||
if (data[0] == 0) break;
|
if (data[0] == 0) break;
|
||||||
|
assert(data.size() >= 6);
|
||||||
data.remove_prefix(4);
|
data.remove_prefix(4);
|
||||||
}
|
}
|
||||||
data.remove_prefix(1);
|
data.remove_prefix(1);
|
||||||
|
Reference in New Issue
Block a user