aboutsummaryrefslogtreecommitdiff
path: root/src/ir_print.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2017-03-26 21:07:07 -0400
committerAndrew Kelley <superjoe30@gmail.com>2017-03-26 21:07:07 -0400
commita32b5929ccf8cbf79396d8924097a1a911985dac (patch)
treec45c7413d1fb6eab9ba102f3a0b7d48df1738164 /src/ir_print.cpp
parent8aeea72654b2efbd068abe207b42170c4d27ee03 (diff)
downloadzig-a32b5929ccf8cbf79396d8924097a1a911985dac.tar.gz
zig-a32b5929ccf8cbf79396d8924097a1a911985dac.zip
add stack protector safety when linking libc
* introduce zigrt file. it contains only weak symbols so that multiple instances can be merged. it contains __zig_panic so that multiple .o files can call the same panic function. * remove `@setFnVisible` builtin and add @setGlobalLinkage builtin which is more powerful * add `@panic` builtin function. * fix collision of symbols with extern prototypes and internal function names * add stack protector safety when linking against libc. To add the safety mechanism without libc requires implementing Thread Local Storage. See #276
Diffstat (limited to 'src/ir_print.cpp')
-rw-r--r--src/ir_print.cpp31
1 files changed, 20 insertions, 11 deletions
diff --git a/src/ir_print.cpp b/src/ir_print.cpp
index b0e5fdc6c0..376de228d2 100644
--- a/src/ir_print.cpp
+++ b/src/ir_print.cpp
@@ -339,14 +339,6 @@ static void ir_print_enum_field_ptr(IrPrint *irp, IrInstructionEnumFieldPtr *ins
fprintf(irp->f, ")");
}
-static void ir_print_set_fn_visible(IrPrint *irp, IrInstructionSetFnVisible *instruction) {
- fprintf(irp->f, "@setFnVisible(");
- ir_print_other_instruction(irp, instruction->fn_value);
- fprintf(irp->f, ", ");
- ir_print_other_instruction(irp, instruction->is_visible);
- fprintf(irp->f, ")");
-}
-
static void ir_print_set_debug_safety(IrPrint *irp, IrInstructionSetDebugSafety *instruction) {
fprintf(irp->f, "@setDebugSafety(");
ir_print_other_instruction(irp, instruction->scope_value);
@@ -849,6 +841,13 @@ static void ir_print_set_global_section(IrPrint *irp, IrInstructionSetGlobalSect
fprintf(irp->f, ")");
}
+static void ir_print_set_global_linkage(IrPrint *irp, IrInstructionSetGlobalLinkage *instruction) {
+ fprintf(irp->f, "@setGlobalLinkage(%s,", buf_ptr(instruction->tld->name));
+ ir_print_other_instruction(irp, instruction->value);
+ fprintf(irp->f, ")");
+}
+
+
static void ir_print_decl_ref(IrPrint *irp, IrInstructionDeclRef *instruction) {
const char *ptr_str = instruction->lval.is_ptr ? "ptr " : "";
const char *const_str = instruction->lval.is_const ? "const " : "";
@@ -856,6 +855,13 @@ static void ir_print_decl_ref(IrPrint *irp, IrInstructionDeclRef *instruction) {
fprintf(irp->f, "declref %s%s%s%s", const_str, volatile_str, ptr_str, buf_ptr(instruction->tld->name));
}
+static void ir_print_panic(IrPrint *irp, IrInstructionPanic *instruction) {
+ fprintf(irp->f, "@panic(");
+ ir_print_other_instruction(irp, instruction->msg);
+ fprintf(irp->f, ")");
+}
+
+
static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {
ir_print_prefix(irp, instruction);
switch (instruction->id) {
@@ -933,9 +939,6 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {
case IrInstructionIdEnumFieldPtr:
ir_print_enum_field_ptr(irp, (IrInstructionEnumFieldPtr *)instruction);
break;
- case IrInstructionIdSetFnVisible:
- ir_print_set_fn_visible(irp, (IrInstructionSetFnVisible *)instruction);
- break;
case IrInstructionIdSetDebugSafety:
ir_print_set_debug_safety(irp, (IrInstructionSetDebugSafety *)instruction);
break;
@@ -1128,9 +1131,15 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {
case IrInstructionIdSetGlobalSection:
ir_print_set_global_section(irp, (IrInstructionSetGlobalSection *)instruction);
break;
+ case IrInstructionIdSetGlobalLinkage:
+ ir_print_set_global_linkage(irp, (IrInstructionSetGlobalLinkage *)instruction);
+ break;
case IrInstructionIdDeclRef:
ir_print_decl_ref(irp, (IrInstructionDeclRef *)instruction);
break;
+ case IrInstructionIdPanic:
+ ir_print_panic(irp, (IrInstructionPanic *)instruction);
+ break;
}
fprintf(irp->f, "\n");
}