authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-10-13 11:07:39-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2019-10-13 11:07:39-04:00
log9439bf3809de68a30a73451cc7648a266aba0a36
tree254924500bbeae4756df98d67b54eb454030c391
parentae0628b30cdde8068dbefcbe6827f3339a9da088
parent22e60df68024f3fd72c91ec7b17dbf7abc71c86c
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #3446 from LemonBoy/riscv-things-x

More RISC-V stuff

4 files changed, 28 insertions(+), 7 deletions(-)

lib/std/debug.zig+15-6
...@@ -280,14 +280,23 @@ pub const StackIterator = struct {...@@ -280,14 +280,23 @@ pub const StackIterator = struct {
280 };280 };
281 }281 }
282282
283 // On some architectures such as x86 the frame pointer is the address where
284 // the previous fp is stored, while on some other architectures such as
285 // RISC-V it points to the "top" of the frame, just above where the previous
286 // fp and the return address are stored.
287 const fp_adjust_factor = if (builtin.arch == .riscv32 or builtin.arch == .riscv64)
288 2 * @sizeOf(usize)
289 else
290 0;
291
283 fn next(self: *StackIterator) ?usize {292 fn next(self: *StackIterator) ?usize {
284 if (self.fp == 0) return null;293 if (self.fp < fp_adjust_factor) return null;
285 self.fp = @intToPtr(*const usize, self.fp).*;294 self.fp = @intToPtr(*const usize, self.fp - fp_adjust_factor).*;
286 if (self.fp == 0) return null;295 if (self.fp < fp_adjust_factor) return null;
287296
288 if (self.first_addr) |addr| {297 if (self.first_addr) |addr| {
289 while (self.fp != 0) : (self.fp = @intToPtr(*const usize, self.fp).*) {298 while (self.fp >= fp_adjust_factor) : (self.fp = @intToPtr(*const usize, self.fp - fp_adjust_factor).*) {
290 const return_address = @intToPtr(*const usize, self.fp + @sizeOf(usize)).*;299 const return_address = @intToPtr(*const usize, self.fp - fp_adjust_factor + @sizeOf(usize)).*;
291 if (addr == return_address) {300 if (addr == return_address) {
292 self.first_addr = null;301 self.first_addr = null;
293 return return_address;302 return return_address;
...@@ -295,7 +304,7 @@ pub const StackIterator = struct {...@@ -295,7 +304,7 @@ pub const StackIterator = struct {
295 }304 }
296 }305 }
297306
298 const return_address = @intToPtr(*const usize, self.fp + @sizeOf(usize)).*;307 const return_address = @intToPtr(*const usize, self.fp - fp_adjust_factor + @sizeOf(usize)).*;
299 return return_address;308 return return_address;
300 }309 }
301};310};
lib/std/elf.zig+2
...@@ -338,6 +338,7 @@ pub const Arch = enum {...@@ -338,6 +338,7 @@ pub const Arch = enum {
338 IA_64,338 IA_64,
339 x86_64,339 x86_64,
340 AArch64,340 AArch64,
341 RiscV,
341};342};
342343
343pub const SectionHeader = struct {344pub const SectionHeader = struct {
...@@ -428,6 +429,7 @@ pub const Elf = struct {...@@ -428,6 +429,7 @@ pub const Elf = struct {
428 0x32 => Arch.IA_64,429 0x32 => Arch.IA_64,
429 0x3E => Arch.x86_64,430 0x3E => Arch.x86_64,
430 0xb7 => Arch.AArch64,431 0xb7 => Arch.AArch64,
432 0xf3 => Arch.RiscV,
431 else => return error.InvalidFormat,433 else => return error.InvalidFormat,
432 };434 };
433435
src/analyze.cpp+4-1
...@@ -1787,6 +1787,7 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc...@@ -1787,6 +1787,7 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc
1787 if (!analyze_const_align(g, child_scope, fn_proto->align_expr, &fn_type_id.alignment)) {1787 if (!analyze_const_align(g, child_scope, fn_proto->align_expr, &fn_type_id.alignment)) {
1788 return g->builtin_types.entry_invalid;1788 return g->builtin_types.entry_invalid;
1789 }1789 }
1790 fn_entry->align_bytes = fn_type_id.alignment;
1790 }1791 }
17911792
1792 if (fn_proto->return_var_token != nullptr) {1793 if (fn_proto->return_var_token != nullptr) {
...@@ -3327,7 +3328,9 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {...@@ -3327,7 +3328,9 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {
3327 fn_table_entry->type_entry = analyze_fn_type(g, source_node, child_scope, fn_table_entry);3328 fn_table_entry->type_entry = analyze_fn_type(g, source_node, child_scope, fn_table_entry);
33283329
3329 if (fn_proto->section_expr != nullptr) {3330 if (fn_proto->section_expr != nullptr) {
3330 analyze_const_string(g, child_scope, fn_proto->section_expr, &fn_table_entry->section_name);3331 if (!analyze_const_string(g, child_scope, fn_proto->section_expr, &fn_table_entry->section_name)) {
3332 fn_table_entry->type_entry = g->builtin_types.entry_invalid;
3333 }
3331 }3334 }
33323335
3333 if (fn_table_entry->type_entry->id == ZigTypeIdInvalid) {3336 if (fn_table_entry->type_entry->id == ZigTypeIdInvalid) {
test/stage1/behavior/align.zig+7
...@@ -328,3 +328,10 @@ test "align(@alignOf(T)) T does not force resolution of T" {...@@ -328,3 +328,10 @@ test "align(@alignOf(T)) T does not force resolution of T" {
328 _ = async S.doTheTest();328 _ = async S.doTheTest();
329 expect(S.ok);329 expect(S.ok);
330}330}
331
332test "align(N) on functions" {
333 expect((@ptrToInt(overaligned_fn) & (0x1000 - 1)) == 0);
334}
335fn overaligned_fn() align(0x1000) i32 {
336 return 42;
337}