aboutsummaryrefslogtreecommitdiff
path: root/src/stage1/target.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-04-25 19:12:06 -0400
committerGitHub <noreply@github.com>2021-04-25 19:12:06 -0400
commit2fc6b347ec66650cd1702c63104fc45148658b15 (patch)
treefe102bc1693efb2d3254192ca4f0f10313ed6fd5 /src/stage1/target.cpp
parent6f61594692af846226880e5903ad26a922014d55 (diff)
parent82f1d592fae021fcfc737e3cb6c107b325fcf1ee (diff)
downloadzig-2fc6b347ec66650cd1702c63104fc45148658b15.tar.gz
zig-2fc6b347ec66650cd1702c63104fc45148658b15.zip
Merge pull request #8616 from LemonBoy/fn-align
Function pointer alignment
Diffstat (limited to 'src/stage1/target.cpp')
-rw-r--r--src/stage1/target.cpp33
1 files changed, 32 insertions, 1 deletions
diff --git a/src/stage1/target.cpp b/src/stage1/target.cpp
index 028f6e5fa8..6aa3cfcbd0 100644
--- a/src/stage1/target.cpp
+++ b/src/stage1/target.cpp
@@ -1253,6 +1253,37 @@ bool target_is_ppc(const ZigTarget *target) {
target->arch == ZigLLVM_ppc64le;
}
+// Returns the minimum alignment for every function pointer on the given
+// architecture.
+unsigned target_fn_ptr_align(const ZigTarget *target) {
+ // TODO This is a pessimization but is always correct.
+ return 1;
+}
+
+// Returns the minimum alignment for every function on the given architecture.
unsigned target_fn_align(const ZigTarget *target) {
- return 16;
+ switch (target->arch) {
+ case ZigLLVM_riscv32:
+ case ZigLLVM_riscv64:
+ // TODO If the C extension is not present the value is 4.
+ return 2;
+ case ZigLLVM_ppc:
+ case ZigLLVM_ppcle:
+ case ZigLLVM_ppc64:
+ case ZigLLVM_ppc64le:
+ case ZigLLVM_aarch64:
+ case ZigLLVM_aarch64_be:
+ case ZigLLVM_aarch64_32:
+ case ZigLLVM_sparc:
+ case ZigLLVM_sparcel:
+ case ZigLLVM_sparcv9:
+ case ZigLLVM_mips:
+ case ZigLLVM_mipsel:
+ case ZigLLVM_mips64:
+ case ZigLLVM_mips64el:
+ return 4;
+
+ default:
+ return 1;
+ }
}