* [PATCH] sparse, llvm: Fix SIGSEGV for extern symbols
@ 2012-08-05 19:47 Pekka Enberg
2012-08-19 0:41 ` Jonathan Neuschäfer
0 siblings, 1 reply; 2+ messages in thread
From: Pekka Enberg @ 2012-08-05 19:47 UTC (permalink / raw)
To: linux-sparse
Cc: j.neuschaefer, Pekka Enberg, Christopher Li, Jeff Garzik,
Linus Torvalds
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>
---
sparse-llvm.c | 8 ++++++++
validation/backend/extern.c | 11 +++++++++++
2 files changed, 19 insertions(+), 0 deletions(-)
create mode 100644 validation/backend/extern.c
diff --git a/sparse-llvm.c b/sparse-llvm.c
index 6b94205..5bcc758 100644
--- a/sparse-llvm.c
+++ b/sparse-llvm.c
@@ -335,6 +335,14 @@ static LLVMValueRef pseudo_to_value(struct function *fn, struct instruction *ins
default:
assert(0);
}
+ } else {
+ const char *name = show_ident(sym->ident);
+
+ result = LLVMGetNamedGlobal(fn->module, name);
+ if (!result) {
+ LLVMTypeRef type = symbol_type(fn->module, sym);
+ result = LLVMAddGlobal(fn->module, type, name);
+ }
}
break;
}
diff --git a/validation/backend/extern.c b/validation/backend/extern.c
new file mode 100644
index 0000000..24cbae5
--- /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
+ */
--
1.7.7.6
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] sparse, llvm: Fix SIGSEGV for extern symbols
2012-08-05 19:47 [PATCH] sparse, llvm: Fix SIGSEGV for extern symbols Pekka Enberg
@ 2012-08-19 0:41 ` Jonathan Neuschäfer
0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Neuschäfer @ 2012-08-19 0:41 UTC (permalink / raw)
To: Pekka Enberg
Cc: linux-sparse, j.neuschaefer, Christopher Li, Jeff Garzik,
Linus Torvalds
On Sun, Aug 05, 2012 at 10:47:34PM +0300, Pekka Enberg wrote:
> 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>
This fixes the crash, thanks.
Jonathan
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-08-19 0:41 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-05 19:47 [PATCH] sparse, llvm: Fix SIGSEGV for extern symbols Pekka Enberg
2012-08-19 0:41 ` Jonathan Neuschäfer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).