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 {
280280 };
281281 }
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
283292 fn next(self: *StackIterator) ?usize {
284 if (self.fp == 0) return null;
285 self.fp = @intToPtr(*const usize, self.fp).*;
286 if (self.fp == 0) return null;
293 if (self.fp < fp_adjust_factor) return null;
294 self.fp = @intToPtr(*const usize, self.fp - fp_adjust_factor).*;
295 if (self.fp < fp_adjust_factor) return null;
287296
288297 if (self.first_addr) |addr| {
289 while (self.fp != 0) : (self.fp = @intToPtr(*const usize, self.fp).*) {
290 const return_address = @intToPtr(*const usize, self.fp + @sizeOf(usize)).*;
298 while (self.fp >= fp_adjust_factor) : (self.fp = @intToPtr(*const usize, self.fp - fp_adjust_factor).*) {
299 const return_address = @intToPtr(*const usize, self.fp - fp_adjust_factor + @sizeOf(usize)).*;
291300 if (addr == return_address) {
292301 self.first_addr = null;
293302 return return_address;
......@@ -295,7 +304,7 @@ pub const StackIterator = struct {
295304 }
296305 }
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)).*;
299308 return return_address;
300309 }
301310};
lib/std/elf.zig+2
......@@ -338,6 +338,7 @@ pub const Arch = enum {
338338 IA_64,
339339 x86_64,
340340 AArch64,
341 RiscV,
341342};
342343
343344pub const SectionHeader = struct {
......@@ -428,6 +429,7 @@ pub const Elf = struct {
428429 0x32 => Arch.IA_64,
429430 0x3E => Arch.x86_64,
430431 0xb7 => Arch.AArch64,
432 0xf3 => Arch.RiscV,
431433 else => return error.InvalidFormat,
432434 };
433435
src/analyze.cpp+4-1
......@@ -1787,6 +1787,7 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc
17871787 if (!analyze_const_align(g, child_scope, fn_proto->align_expr, &fn_type_id.alignment)) {
17881788 return g->builtin_types.entry_invalid;
17891789 }
1790 fn_entry->align_bytes = fn_type_id.alignment;
17901791 }
17911792
17921793 if (fn_proto->return_var_token != nullptr) {
......@@ -3327,7 +3328,9 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {
33273328 fn_table_entry->type_entry = analyze_fn_type(g, source_node, child_scope, fn_table_entry);
33283329
33293330 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 }
33313334 }
33323335
33333336 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" {
328328 _ = async S.doTheTest();
329329 expect(S.ok);
330330}
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}