| author | |
| committer | |
| log | 9439bf3809de68a30a73451cc7648a266aba0a36 |
| tree | 254924500bbeae4756df98d67b54eb454030c391 |
| parent | ae0628b30cdde8068dbefcbe6827f3339a9da088 |
| parent | 22e60df68024f3fd72c91ec7b17dbf7abc71c86c |
| signature |
More RISC-V stuff4 files changed, 28 insertions(+), 7 deletions(-)
lib/std/debug.zig+15-6| ... | ... | @@ -280,14 +280,23 @@ pub const StackIterator = struct { |
| 280 | 280 | }; |
| 281 | 281 | } |
| 282 | 282 | |
| 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 | 292 | 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; | |
| 287 | 296 | |
| 288 | 297 | 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)).*; | |
| 291 | 300 | if (addr == return_address) { |
| 292 | 301 | self.first_addr = null; |
| 293 | 302 | return return_address; |
| ... | ... | @@ -295,7 +304,7 @@ pub const StackIterator = struct { |
| 295 | 304 | } |
| 296 | 305 | } |
| 297 | 306 | |
| 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 | 308 | return return_address; |
| 300 | 309 | } |
| 301 | 310 | }; |
lib/std/elf.zig+2| ... | ... | @@ -338,6 +338,7 @@ pub const Arch = enum { |
| 338 | 338 | IA_64, |
| 339 | 339 | x86_64, |
| 340 | 340 | AArch64, |
| 341 | RiscV, | |
| 341 | 342 | }; |
| 342 | 343 | |
| 343 | 344 | pub const SectionHeader = struct { |
| ... | ... | @@ -428,6 +429,7 @@ pub const Elf = struct { |
| 428 | 429 | 0x32 => Arch.IA_64, |
| 429 | 430 | 0x3E => Arch.x86_64, |
| 430 | 431 | 0xb7 => Arch.AArch64, |
| 432 | 0xf3 => Arch.RiscV, | |
| 431 | 433 | else => return error.InvalidFormat, |
| 432 | 434 | }; |
| 433 | 435 |
src/analyze.cpp+4-1| ... | ... | @@ -1787,6 +1787,7 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc |
| 1787 | 1787 | if (!analyze_const_align(g, child_scope, fn_proto->align_expr, &fn_type_id.alignment)) { |
| 1788 | 1788 | return g->builtin_types.entry_invalid; |
| 1789 | 1789 | } |
| 1790 | fn_entry->align_bytes = fn_type_id.alignment; | |
| 1790 | 1791 | } |
| 1791 | 1792 | |
| 1792 | 1793 | if (fn_proto->return_var_token != nullptr) { |
| ... | ... | @@ -3327,7 +3328,9 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) { |
| 3327 | 3328 | fn_table_entry->type_entry = analyze_fn_type(g, source_node, child_scope, fn_table_entry); |
| 3328 | 3329 | |
| 3329 | 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 | } |
| 3332 | 3335 | |
| 3333 | 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 | 328 | _ = async S.doTheTest(); |
| 329 | 329 | expect(S.ok); |
| 330 | 330 | } |
| 331 | ||
| 332 | test "align(N) on functions" { | |
| 333 | expect((@ptrToInt(overaligned_fn) & (0x1000 - 1)) == 0); | |
| 334 | } | |
| 335 | fn overaligned_fn() align(0x1000) i32 { | |
| 336 | return 42; | |
| 337 | } |