Skip to contentSkip to conversation

sparse, llvm: Fix symbol initializer code generation

PATCH New Pekka Enberg 1 participant 3 messages Nov 21, 2011 Sparse checker

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 sparse, llvm: Fix symbol initializer code generation

The output_data() function does not see right hand side symbols for expressions such as this in target.c:

  struct symbol *size_t_ctype = &uint_ctype;

Therefore, call output_data() recursively if LLVMGetNamedGlobal() returns NULL for a symbol.

Cc Christopher Li <[email protected]>
Cc Jeff Garzik <[email protected]>
Cc Linus Torvalds <[email protected]>
---
 sparse-llvm.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
sparse-llvm.c +4 -2
index c037e02..ca49a6e 100644
@@ -1055,7 +1055,7 @@ static void output_fn(LLVMModuleRef module, struct entrypoint *ep)
 	END_FOR_EACH_PTR(bb);
 }
 
-static int output_data(LLVMModuleRef module, struct symbol *sym)
+static LLVMValueRef output_data(LLVMModuleRef module, struct symbol *sym)
 {
 	struct expression *initializer = sym->initializer;
 	LLVMValueRef initial_value;
@@ -1071,6 +1071,8 @@ static int output_data(LLVMModuleRef module, struct symbol *sym)
 			struct symbol *sym = initializer->symbol;
 
 			initial_value = LLVMGetNamedGlobal(module, show_ident(sym->ident));
+			if (!initial_value)
+				initial_value = output_data(module, sym);
 			break;
 		}
 		default:
@@ -1090,7 +1092,7 @@ static int output_data(LLVMModuleRef module, struct symbol *sym)
 
 	LLVMSetInitializer(data, initial_value);
 
-	return 0;
+	return data;
 }
 
 static int compile(LLVMModuleRef module, struct symbol_list *list)
Signature · 1 line
1.7.6.4
#1 lore raw

PATCH 2/3 sparse, llvm: Fix 'extern' symbol code generation

LLVMExternalLinkage is used for both extern and non-extern C symbols. The linkage is differentiated by LLVMSetInitializer() which is should not be called for extern symbols.

Cc Christopher Li <[email protected]>
Cc Jeff Garzik <[email protected]>
Cc Linus Torvalds <[email protected]>
---
 sparse-llvm.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
sparse-llvm.c +2 -1
index ca49a6e..1a2a34d 100644
@@ -1090,7 +1090,8 @@ static LLVMValueRef output_data(LLVMModuleRef module, struct symbol *sym)
 
 	LLVMSetLinkage(data, data_linkage(sym));
 
-	LLVMSetInitializer(data, initial_value);
+	if (!(sym->ctype.modifiers & MOD_EXTERN))
+		LLVMSetInitializer(data, initial_value);
 
 	return data;
 }
Signature · 1 line
1.7.6.4
#2 lore raw

PATCH 3/3 sparse, llvm: Make llc output to stdout in sparsec

In reply to Pekka Enberg

This patch fixes a bug in 'sparsec' that made it generate empty object files.

Cc Christopher Li <[email protected]>
Cc Jeff Garzik <[email protected]>
Cc Linus Torvalds <[email protected]>
---
 sparsec |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
sparsec +1 -1
index 33e1a2b..9c90b30 100755
@@ -34,7 +34,7 @@ TMPFILE=`mktemp -t tmp.XXXXXX`".o"
 
 $DIRNAME/sparse-llvm $SPARSEOPTS > $TMPLLVM
 
-llc $TMPLLVM | as -o $TMPFILE
+llc -o - $TMPLLVM | as -o $TMPFILE
 
 if [ $NEED_LINK -eq 1 ]; then
 	if [ -z $OUTFILE ]; then
Signature · 1 line
1.7.6.4