Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes to 32-bit handling, to support 32-bit arm #4870

Merged
merged 1 commit into from
Mar 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions lib/std/zig/system.zig
Original file line number Diff line number Diff line change
Expand Up @@ -622,9 +622,10 @@ pub const NativeTargetInfo = struct {
const p_offset = elfInt(is_64, need_bswap, ph32.p_offset, ph64.p_offset);
const p_filesz = elfInt(is_64, need_bswap, ph32.p_filesz, ph64.p_filesz);
if (p_filesz > result.dynamic_linker.buffer.len) return error.NameTooLong;
_ = try preadMin(file, result.dynamic_linker.buffer[0..p_filesz], p_offset, p_filesz);
// PT_INTERP includes a null byte in p_filesz.
const len = p_filesz - 1;
const filesz = @intCast(usize, p_filesz);
_ = try preadMin(file, result.dynamic_linker.buffer[0..filesz], p_offset, filesz);
// PT_INTERP includes a null byte in filesz.
const len = filesz - 1;
// dynamic_linker.max_byte is "max", not "len".
// We know it will fit in u8 because we check against dynamic_linker.buffer.len above.
result.dynamic_linker.max_byte = @intCast(u8, len - 1);
Expand All @@ -645,7 +646,7 @@ pub const NativeTargetInfo = struct {
{
var dyn_off = elfInt(is_64, need_bswap, ph32.p_offset, ph64.p_offset);
const p_filesz = elfInt(is_64, need_bswap, ph32.p_filesz, ph64.p_filesz);
const dyn_size: u64 = if (is_64) @sizeOf(elf.Elf64_Dyn) else @sizeOf(elf.Elf32_Dyn);
const dyn_size: usize = if (is_64) @sizeOf(elf.Elf64_Dyn) else @sizeOf(elf.Elf32_Dyn);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does peer-type resolution not work here? (i.e. omit the type?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is_64 is runtime known, so it hits #137

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh interesting. I thought @sizeOf would return a comptime-known usize rather than a comptime_int

const dyn_num = p_filesz / dyn_size;
var dyn_buf: [16 * @sizeOf(elf.Elf64_Dyn)]u8 align(@alignOf(elf.Elf64_Dyn)) = undefined;
var dyn_i: usize = 0;
Expand Down Expand Up @@ -751,7 +752,10 @@ pub const NativeTargetInfo = struct {
const strtab_read_len = try preadMin(file, &strtab_buf, ds.offset, shstrtab_len);
const strtab = strtab_buf[0..strtab_read_len];
// TODO this pointer cast should not be necessary
const rpath_list = mem.spanZ(@ptrCast([*:0]u8, strtab[rpoff..].ptr));
const rpoff_usize = std.math.cast(usize, rpoff) catch |err| switch (err) {
error.Overflow => return error.InvalidElfFile,
};
const rpath_list = mem.spanZ(@ptrCast([*:0]u8, strtab[rpoff_usize..].ptr));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this was strtab[rpoff_usize..:0]. could we remove the @ptrCast? (and TODO above)

var it = mem.tokenize(rpath_list, ":");
while (it.next()) |rpath| {
var dir = fs.cwd().openDir(rpath, .{}) catch |err| switch (err) {
Expand Down Expand Up @@ -811,7 +815,7 @@ pub const NativeTargetInfo = struct {
}

fn preadMin(file: fs.File, buf: []u8, offset: u64, min_read_len: usize) !usize {
var i: u64 = 0;
var i: usize = 0;

This comment was marked as resolved.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fn is allowed to return short reads. i is just an offset, which is relative to min_read_len. usize was the correct type all along.

while (i < min_read_len) {
const len = file.pread(buf[i .. buf.len - i], offset + i) catch |err| switch (err) {
error.OperationAborted => unreachable, // Windows-only
Expand Down
26 changes: 23 additions & 3 deletions src-self-hosted/translate_c.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3845,7 +3845,9 @@ fn transCreateNodePtrType(
}

fn transCreateNodeAPInt(c: *Context, int: *const ZigClangAPSInt) !*ast.Node {
const num_limbs = ZigClangAPSInt_getNumWords(int);
const num_limbs = math.cast(usize, ZigClangAPSInt_getNumWords(int)) catch |err| switch (err) {
error.Overflow => return error.OutOfMemory,
};
var aps_int = int;
const is_negative = ZigClangAPSInt_isSigned(int) and ZigClangAPSInt_isNegative(int);
if (is_negative)
Expand All @@ -3855,8 +3857,26 @@ fn transCreateNodeAPInt(c: *Context, int: *const ZigClangAPSInt) !*ast.Node {
big.negate();
defer big.deinit();
const data = ZigClangAPSInt_getRawData(aps_int);
var i: @TypeOf(num_limbs) = 0;
while (i < num_limbs) : (i += 1) big.limbs[i] = data[i];
switch (@sizeOf(std.math.big.Limb)) {
8 => {
var i: usize = 0;
while (i < num_limbs) : (i += 1) {
big.limbs[i] = data[i];
}
},
4 => {
var limb_i: usize = 0;
var data_i: usize = 0;
while (limb_i < num_limbs) : ({
limb_i += 2;
data_i += 1;
}) {
big.limbs[limb_i] = @truncate(u32, data[data_i]);
big.limbs[limb_i + 1] = @truncate(u32, data[data_i] >> 32);
}
},
else => @compileError("unimplemented"),
}
const str = big.toString(c.a(), 10) catch |err| switch (err) {
error.OutOfMemory => return error.OutOfMemory,
else => unreachable,
Expand Down
1 change: 1 addition & 0 deletions src/link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,7 @@ static const char *build_libunwind(CodeGen *parent, Stage2ProgressNode *progress
if (parent->is_single_threaded) {
c_file->args.append("-D_LIBUNWIND_HAS_NO_THREADS");
}
c_file->args.append("-Wno-bitwise-conditional-parentheses");
c_source_files.append(c_file);
}
child_gen->c_source_files = c_source_files;
Expand Down
4 changes: 2 additions & 2 deletions src/os.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1097,8 +1097,8 @@ static Error set_file_times(OsFile file, OsTimeStamp ts) {
return ErrorNone;
#else
struct timespec times[2] = {
{ (time_t)ts.sec, (time_t)ts.nsec },
{ (time_t)ts.sec, (time_t)ts.nsec },
{ (time_t)ts.sec, (long)ts.nsec },
{ (time_t)ts.sec, (long)ts.nsec },
};
if (futimens(file, times) == -1) {
switch (errno) {
Expand Down