From 2c67cc3eb95cd536a4331fd5de6ff09b07327d01 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Mon, 10 Jun 2019 13:16:27 +0300 Subject: [PATCH] C: fix initialization order of system classes --- core/src/main/java/org/teavm/backend/c/CTarget.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/core/src/main/java/org/teavm/backend/c/CTarget.java b/core/src/main/java/org/teavm/backend/c/CTarget.java index 9e883af3d..77aed11c8 100644 --- a/core/src/main/java/org/teavm/backend/c/CTarget.java +++ b/core/src/main/java/org/teavm/backend/c/CTarget.java @@ -122,6 +122,7 @@ import org.teavm.runtime.CallSiteLocation; import org.teavm.runtime.EventQueue; import org.teavm.runtime.ExceptionHandling; import org.teavm.runtime.Fiber; +import org.teavm.runtime.GC; import org.teavm.runtime.RuntimeArray; import org.teavm.runtime.RuntimeClass; import org.teavm.runtime.RuntimeObject; @@ -739,7 +740,17 @@ public class CTarget implements TeaVMTarget, TeaVMCHost { private void generateStaticInitializerCalls(GenerationContext context, CodeWriter writer, IncludeManager includes, ListableClassReaderSource classes) { MethodDescriptor clinitDescriptor = new MethodDescriptor("", ValueType.VOID); + if (classes.getClassNames().contains(GC.class.getName())) { + includes.includeClass(GC.class.getName()); + String clinitName = context.getNames().forMethod(new MethodReference(GC.class.getName(), + clinitDescriptor)); + writer.println(clinitName + "();"); + } + for (String className : classes.getClassNames()) { + if (className.equals(GC.class.getName())) { + continue; + } ClassReader cls = classes.get(className); if (!context.getCharacteristics().isStaticInit(cls.getName()) && !context.getCharacteristics().isStructure(cls.getName())) {