@@ -42,6 +42,7 @@ type object struct {
42
42
globalName string // name, if not yet created (not guaranteed to be the final name)
43
43
buffer value // buffer with value as given by interp, nil if external
44
44
size uint32 // must match buffer.len(), if available
45
+ align int // alignment of the object (may be 0 if unknown)
45
46
constant bool // true if this is a constant global
46
47
marked uint8 // 0 means unmarked, 1 means external read, 2 means external write
47
48
}
@@ -593,6 +594,12 @@ func (v pointerValue) toLLVMValue(llvmType llvm.Type, mem *memoryView) (llvm.Val
593
594
// runtime.alloc.
594
595
// First allocate a new global for this object.
595
596
obj := mem .get (v .index ())
597
+ alignment := obj .align
598
+ if alignment == 0 {
599
+ // Unknown alignment, perhaps from a direct call to runtime.alloc in
600
+ // the runtime. Use a conservative default instead.
601
+ alignment = mem .r .maxAlign
602
+ }
596
603
if obj .llvmType .IsNil () && obj .llvmLayoutType .IsNil () {
597
604
// Create an initializer without knowing the global type.
598
605
// This is probably the result of a runtime.alloc call.
@@ -603,7 +610,7 @@ func (v pointerValue) toLLVMValue(llvmType llvm.Type, mem *memoryView) (llvm.Val
603
610
globalType := initializer .Type ()
604
611
llvmValue = llvm .AddGlobal (mem .r .mod , globalType , obj .globalName )
605
612
llvmValue .SetInitializer (initializer )
606
- llvmValue .SetAlignment (mem . r . maxAlign )
613
+ llvmValue .SetAlignment (alignment )
607
614
obj .llvmGlobal = llvmValue
608
615
mem .put (v .index (), obj )
609
616
} else {
@@ -642,11 +649,7 @@ func (v pointerValue) toLLVMValue(llvmType llvm.Type, mem *memoryView) (llvm.Val
642
649
return llvm.Value {}, errors .New ("interp: allocated value does not match allocated type" )
643
650
}
644
651
llvmValue .SetInitializer (initializer )
645
- if obj .llvmType .IsNil () {
646
- // The exact type isn't known (only the layout), so use the
647
- // alignment that would normally be expected from runtime.alloc.
648
- llvmValue .SetAlignment (mem .r .maxAlign )
649
- }
652
+ llvmValue .SetAlignment (alignment )
650
653
}
651
654
652
655
// It should be included in r.globals because otherwise markExternal
0 commit comments