aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/validation/backend/extern.c
diff options
authorPekka Enberg <penberg@kernel.org>2012-08-05 22:42:46 +0300
committerPekka Enberg <penberg@kernel.org>2012-08-05 22:48:32 +0300
commit14d9355b4a2c6b25f4381ad6ac8b51715382703c (patch)
tree5910a227863df6dfad3d3539fb059617af52ef92 /validation/backend/extern.c
parentccf42dc22ef4354ef6db1673a5e2b2bc0a6be273 (diff)
downloadsparse-dev-14d9355b4a2c6b25f4381ad6ac8b51715382703c.tar.gz
sparse, llvm: Fix SIGSEGV for extern symbols
Jonathan Neuschäfer writes: compiling a little real-world program with sparse-llvm, it segfaulted. Using a tool called "delta"[1] and some bash scripting, I managed to reduce the code to this test case: extern struct foo *foop; extern void func(struct foo *f); int main(int argc, char **argv) { func(foop); } The problem is that pseudo_to_value() does not know abou the extern symbol because Sparse never calls output_data() on it which registers globals with LLVMAddGlobal(). As explained by Linus, 'extern' symbols are just names with types. They don't have any value associated with them, they just have the type and the name. Therefore we need to explicitly call LLVMAddGlobal() for symbols we have not encountered in pseudo_to_value(). Reported by: Jonathan Neuschäfer <j.neuschaefer@gmx.net> Cc: Christopher Li <sparse@chrisli.org> Cc: Jeff Garzik <jgarzik@redhat.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Pekka Enberg <penberg@kernel.org>
Diffstat (limited to 'validation/backend/extern.c')
-rw-r--r--validation/backend/extern.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/validation/backend/extern.c b/validation/backend/extern.c
new file mode 100644
index 00000000..24cbae55
--- /dev/null
+++ b/validation/backend/extern.c
@@ -0,0 +1,11 @@
+extern unsigned long foo;
+
+static unsigned long bar(void)
+{
+ return foo;
+}
+
+/*
+ * check-name: Extern symbol code generation
+ * check-command: ./sparsec -c $file -o tmp.o
+ */