mirror of
https://github.com/rui314/mold.git
synced 2024-09-22 02:20:51 +03:00
temporary
This commit is contained in:
parent
ebc006abef
commit
540506d33c
@ -34,31 +34,31 @@ static std::string rel_to_string(u32 r_type) {
|
||||
unreachable();
|
||||
}
|
||||
|
||||
static void overflow_check(std::ostringstream &out, u32 r_type, u64 val) {
|
||||
static void overflow_check(std::ostringstream &out, u32 r_type, u8 *loc, u64 val) {
|
||||
switch (r_type) {
|
||||
case R_X86_64_8:
|
||||
if (val != (u8)val)
|
||||
out << "relocation R_X86_64_8 out of range: " << val << " is not in [0, 255]";
|
||||
return;
|
||||
break;
|
||||
case R_X86_64_PC8:
|
||||
if (val != (i8)val)
|
||||
out << "relocation R_X86_64_PC8 out of range: " << (i64)val
|
||||
<< " is not in [-128, 127]";
|
||||
return;
|
||||
break;
|
||||
case R_X86_64_16:
|
||||
if (val != (u16)val)
|
||||
out << "relocation R_X86_64_16 out of range: " << val << " is not in [0, 65535]";
|
||||
return;
|
||||
break;
|
||||
case R_X86_64_PC16:
|
||||
if (val != (i16)val)
|
||||
out << "relocation R_X86_64_PC16 out of range: " << (i64)val
|
||||
<< " is not in [-32768, 32767]";
|
||||
return;
|
||||
break;
|
||||
case R_X86_64_32:
|
||||
if (val != (u32)val)
|
||||
out << "relocation R_X86_64_32 out of range: " << val
|
||||
<< " is not in [0, 4294967296]";
|
||||
return;
|
||||
break;
|
||||
case R_X86_64_32S:
|
||||
case R_X86_64_PC32:
|
||||
case R_X86_64_GOT32:
|
||||
@ -75,27 +75,30 @@ static void overflow_check(std::ostringstream &out, u32 r_type, u64 val) {
|
||||
if (val != (i32)val)
|
||||
out << "relocation " << rel_to_string(r_type) << " out of range: "
|
||||
<< (i64)val << " is not in [-2147483648, 2147483647]";
|
||||
return;
|
||||
break;
|
||||
case R_X86_64_NONE:
|
||||
case R_X86_64_64:
|
||||
case R_X86_64_PC64:
|
||||
case R_X86_64_TPOFF64:
|
||||
case R_X86_64_DTPOFF64:
|
||||
return;
|
||||
break;
|
||||
default:
|
||||
unreachable();
|
||||
}
|
||||
unreachable();
|
||||
}
|
||||
|
||||
static int get_rel_size(u32 r_type) {
|
||||
static void write_val(u32 r_type, u8 *loc, u64 val) {
|
||||
switch (r_type) {
|
||||
case R_X86_64_NONE:
|
||||
return 0;
|
||||
break;
|
||||
case R_X86_64_8:
|
||||
case R_X86_64_PC8:
|
||||
return 1;
|
||||
*loc = val;
|
||||
break;
|
||||
case R_X86_64_16:
|
||||
case R_X86_64_PC16:
|
||||
return 2;
|
||||
*(u16 *)loc = val;
|
||||
break;
|
||||
case R_X86_64_32:
|
||||
case R_X86_64_32S:
|
||||
case R_X86_64_PC32:
|
||||
@ -110,14 +113,17 @@ static int get_rel_size(u32 r_type) {
|
||||
case R_X86_64_TPOFF32:
|
||||
case R_X86_64_DTPOFF32:
|
||||
case R_X86_64_GOTTPOFF:
|
||||
return 4;
|
||||
*(u32 *)loc = val;
|
||||
break;
|
||||
case R_X86_64_64:
|
||||
case R_X86_64_PC64:
|
||||
case R_X86_64_TPOFF64:
|
||||
case R_X86_64_DTPOFF64:
|
||||
return 8;
|
||||
*(u64 *)loc = val;
|
||||
break;
|
||||
default:
|
||||
unreachable();
|
||||
}
|
||||
unreachable();
|
||||
}
|
||||
|
||||
void InputSection::copy_buf() {
|
||||
@ -148,14 +154,8 @@ void InputSection::copy_buf() {
|
||||
ref = &rel_pieces[ref_idx++];
|
||||
|
||||
auto write = [&](u64 val) {
|
||||
overflow_check(file->err_out, rel.r_type, val);
|
||||
switch (get_rel_size(rel.r_type)) {
|
||||
case 1: *loc = val; return;
|
||||
case 2: *(u16 *)loc = val; return;
|
||||
case 4: *(u32 *)loc = val; return;
|
||||
case 8: *(u64 *)loc = val; return;
|
||||
}
|
||||
unreachable();
|
||||
overflow_check(file->err_out, rel.r_type, loc, val);
|
||||
write_val(rel.r_type, loc, val);
|
||||
};
|
||||
|
||||
#define S (ref ? ref->piece->get_addr() : sym.get_addr())
|
||||
@ -172,7 +172,6 @@ void InputSection::copy_buf() {
|
||||
write(S + A);
|
||||
|
||||
if (sym.needs_relative_rel()) {
|
||||
assert(get_rel_size(rel.r_type) == 8);
|
||||
memset(dynrel, 0, sizeof(*dynrel));
|
||||
dynrel->r_offset = P;
|
||||
dynrel->r_type = R_X86_64_RELATIVE;
|
||||
|
Loading…
Reference in New Issue
Block a user