From 572b628118be603f280083d2873553c8bb839d4a Mon Sep 17 00:00:00 2001 From: Paley Li Date: Thu, 11 Feb 2021 11:09:01 +0100 Subject: [PATCH 1/5] Sulong: allow external weak functions --- .../parser/factories/BasicNodeFactory.java | 2 +- .../truffle/llvm/parser/LLVMParser.java | 5 +++-- .../llvm/parser/model/GlobalSymbol.java | 2 ++ .../model/functions/FunctionDeclaration.java | 5 +++++ .../model/functions/FunctionDefinition.java | 5 +++++ .../symbols/globals/GlobalValueSymbol.java | 5 +++++ .../truffle/llvm/runtime/LLVMAlias.java | 2 +- .../truffle/llvm/runtime/LLVMFunction.java | 8 ++++---- .../truffle/llvm/runtime/LLVMSymbol.java | 8 +++++++- .../llvm/runtime/global/LLVMGlobal.java | 10 +++++----- .../interop/LLVMTruffleDecorateFunction.java | 2 +- .../com/oracle/truffle/llvm/ParserDriver.java | 6 +++--- .../AllocExternalSymbolNode.java | 20 +++++++++++++++++++ 13 files changed, 62 insertions(+), 18 deletions(-) diff --git a/sulong/projects/com.oracle.truffle.llvm.parser.factories/src/com/oracle/truffle/llvm/parser/factories/BasicNodeFactory.java b/sulong/projects/com.oracle.truffle.llvm.parser.factories/src/com/oracle/truffle/llvm/parser/factories/BasicNodeFactory.java index a3224f38ae8e..ffe4d1902bb5 100644 --- a/sulong/projects/com.oracle.truffle.llvm.parser.factories/src/com/oracle/truffle/llvm/parser/factories/BasicNodeFactory.java +++ b/sulong/projects/com.oracle.truffle.llvm.parser.factories/src/com/oracle/truffle/llvm/parser/factories/BasicNodeFactory.java @@ -1193,7 +1193,7 @@ public LLVMExpressionNode createInlineAssemblerExpression(String asmExpression, } LLVMIRFunction function = new LLVMIRFunction(LLVMLanguage.createCallTarget(assemblyRoot), null); LLVMFunction functionDetail = LLVMFunction.create("", function, new FunctionType(MetaType.UNKNOWN, 0, false), LLVMSymbol.INVALID_INDEX, LLVMSymbol.INVALID_INDEX, - false, assemblyRoot.getName()); + false, assemblyRoot.getName(), false); // The function descriptor for the inline assembly does not require a language. LLVMFunctionDescriptor asm = new LLVMFunctionDescriptor(functionDetail, new LLVMFunctionCode(functionDetail)); LLVMManagedPointerLiteralNode asmFunction = LLVMManagedPointerLiteralNodeGen.create(LLVMManagedPointer.create(asm)); diff --git a/sulong/projects/com.oracle.truffle.llvm.parser/src/com/oracle/truffle/llvm/parser/LLVMParser.java b/sulong/projects/com.oracle.truffle.llvm.parser/src/com/oracle/truffle/llvm/parser/LLVMParser.java index 514a53113f62..a5051e6f86e0 100644 --- a/sulong/projects/com.oracle.truffle.llvm.parser/src/com/oracle/truffle/llvm/parser/LLVMParser.java +++ b/sulong/projects/com.oracle.truffle.llvm.parser/src/com/oracle/truffle/llvm/parser/LLVMParser.java @@ -110,7 +110,8 @@ private void defineAliases(List aliases) { private void defineGlobal(GlobalVariable global) { assert !global.isExternal(); // handle the file scope - LLVMGlobal globalSymbol = LLVMGlobal.create(global.getName(), global.getType(), global.getSourceSymbol(), global.isReadOnly(), global.getIndex(), runtime.getBitcodeID(), global.isExported()); + LLVMGlobal globalSymbol = LLVMGlobal.create(global.getName(), global.getType(), global.getSourceSymbol(), global.isReadOnly(), global.getIndex(), runtime.getBitcodeID(), global.isExported(), + global.isExternalWeak()); runtime.getFileScope().register(globalSymbol); } @@ -122,7 +123,7 @@ private void defineFunction(FunctionSymbol functionSymbol, ModelModule model, Da model.getFunctionProcessor(), dataLayout); Function function = new LazyLLVMIRFunction(lazyConverter); LLVMFunction llvmFunction = LLVMFunction.create(functionSymbol.getName(), function, functionSymbol.getType(), runtime.getBitcodeID(), functionSymbol.getIndex(), - functionDefinition.isExported(), runtime.getFile().getPath()); + functionDefinition.isExported(), runtime.getFile().getPath(), functionDefinition.isExternalWeak()); lazyConverter.setRootFunction(llvmFunction); runtime.getFileScope().register(llvmFunction); final boolean cxxInterop = LLVMLanguage.getContext().getEnv().getOptions().get(SulongEngineOption.CXX_INTEROP); diff --git a/sulong/projects/com.oracle.truffle.llvm.parser/src/com/oracle/truffle/llvm/parser/model/GlobalSymbol.java b/sulong/projects/com.oracle.truffle.llvm.parser/src/com/oracle/truffle/llvm/parser/model/GlobalSymbol.java index 76f7638407ee..7c41ff5f7d8c 100644 --- a/sulong/projects/com.oracle.truffle.llvm.parser/src/com/oracle/truffle/llvm/parser/model/GlobalSymbol.java +++ b/sulong/projects/com.oracle.truffle.llvm.parser/src/com/oracle/truffle/llvm/parser/model/GlobalSymbol.java @@ -94,4 +94,6 @@ public final int getIndex() { public abstract boolean isExternal(); + public abstract boolean isExternalWeak(); + } diff --git a/sulong/projects/com.oracle.truffle.llvm.parser/src/com/oracle/truffle/llvm/parser/model/functions/FunctionDeclaration.java b/sulong/projects/com.oracle.truffle.llvm.parser/src/com/oracle/truffle/llvm/parser/model/functions/FunctionDeclaration.java index 635f65a31efb..68170a0e7fad 100644 --- a/sulong/projects/com.oracle.truffle.llvm.parser/src/com/oracle/truffle/llvm/parser/model/functions/FunctionDeclaration.java +++ b/sulong/projects/com.oracle.truffle.llvm.parser/src/com/oracle/truffle/llvm/parser/model/functions/FunctionDeclaration.java @@ -84,6 +84,11 @@ public boolean isExternal() { return true; } + @Override + public boolean isExternalWeak() { + return getLinkage() == Linkage.EXTERN_WEAK; + } + @Override public LLVMExpressionNode createNode(LLVMParserRuntime runtime, DataLayout dataLayout, GetStackSpaceFactory stackFactory) { LLVMFunction value = runtime.lookupFunction(getName()); diff --git a/sulong/projects/com.oracle.truffle.llvm.parser/src/com/oracle/truffle/llvm/parser/model/functions/FunctionDefinition.java b/sulong/projects/com.oracle.truffle.llvm.parser/src/com/oracle/truffle/llvm/parser/model/functions/FunctionDefinition.java index 0ba3129f7a2f..fbfb2ecc8841 100644 --- a/sulong/projects/com.oracle.truffle.llvm.parser/src/com/oracle/truffle/llvm/parser/model/functions/FunctionDefinition.java +++ b/sulong/projects/com.oracle.truffle.llvm.parser/src/com/oracle/truffle/llvm/parser/model/functions/FunctionDefinition.java @@ -224,6 +224,11 @@ public boolean isExternal() { return Linkage.isExternal(getLinkage()); } + @Override + public boolean isExternalWeak() { + return getLinkage() == Linkage.EXTERN_WEAK; + } + @Override public LLVMExpressionNode createNode(LLVMParserRuntime runtime, DataLayout dataLayout, GetStackSpaceFactory stackFactory) { LLVMFunction value = runtime.lookupFunction(getName()); diff --git a/sulong/projects/com.oracle.truffle.llvm.parser/src/com/oracle/truffle/llvm/parser/model/symbols/globals/GlobalValueSymbol.java b/sulong/projects/com.oracle.truffle.llvm.parser/src/com/oracle/truffle/llvm/parser/model/symbols/globals/GlobalValueSymbol.java index 4a0ed4ac0d32..834976196144 100644 --- a/sulong/projects/com.oracle.truffle.llvm.parser/src/com/oracle/truffle/llvm/parser/model/symbols/globals/GlobalValueSymbol.java +++ b/sulong/projects/com.oracle.truffle.llvm.parser/src/com/oracle/truffle/llvm/parser/model/symbols/globals/GlobalValueSymbol.java @@ -133,4 +133,9 @@ public boolean isOverridable() { public boolean isExternal() { return getInitialiser() == 0 && isExported(); } + + @Override + public boolean isExternalWeak() { + return getLinkage() == Linkage.EXTERN_WEAK; + } } diff --git a/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/LLVMAlias.java b/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/LLVMAlias.java index b2283afc4253..3823998ed14b 100644 --- a/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/LLVMAlias.java +++ b/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/LLVMAlias.java @@ -40,7 +40,7 @@ public class LLVMAlias extends LLVMSymbol { @CompilationFinal private LLVMSymbol target; public LLVMAlias(String name, LLVMSymbol target, boolean exported) { - super(name, LLVMSymbol.INVALID_ID, LLVMSymbol.INVALID_ID, exported); + super(name, LLVMSymbol.INVALID_ID, LLVMSymbol.INVALID_ID, exported, false); setTarget(target); } diff --git a/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/LLVMFunction.java b/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/LLVMFunction.java index b8d0e83d610d..9d7366069a5b 100644 --- a/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/LLVMFunction.java +++ b/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/LLVMFunction.java @@ -55,12 +55,12 @@ public final class LLVMFunction extends LLVMSymbol { private final Assumption fixedCodeAssumption = Truffle.getRuntime().createAssumption(); @CompilationFinal private LLVMFunctionCode fixedCode; - public static LLVMFunction create(String name, Function function, FunctionType type, int bitcodeID, int symbolIndex, boolean exported, String path) { - return new LLVMFunction(name, function, type, bitcodeID, symbolIndex, exported, path); + public static LLVMFunction create(String name, Function function, FunctionType type, int bitcodeID, int symbolIndex, boolean exported, String path, boolean externalWeak) { + return new LLVMFunction(name, function, type, bitcodeID, symbolIndex, exported, path, externalWeak); } - public LLVMFunction(String name, Function function, FunctionType type, int bitcodeID, int symbolIndex, boolean exported, String path) { - super(name, bitcodeID, symbolIndex, exported); + public LLVMFunction(String name, Function function, FunctionType type, int bitcodeID, int symbolIndex, boolean exported, String path, boolean externalWeak) { + super(name, bitcodeID, symbolIndex, exported, externalWeak); this.type = type; this.function = function; this.path = path; diff --git a/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/LLVMSymbol.java b/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/LLVMSymbol.java index 4200b4b12184..6f97deab943d 100644 --- a/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/LLVMSymbol.java +++ b/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/LLVMSymbol.java @@ -42,6 +42,7 @@ public abstract class LLVMSymbol { private final int moduleId; private final int symbolIndex; private final boolean exported; + private final boolean externalWeak; // Index for non-parsed symbols, such as alias, and function symbol for inline assembly. public static final int INVALID_INDEX = -1; @@ -49,11 +50,12 @@ public abstract class LLVMSymbol { // ID for non-parsed symbols, such as alias, function symbol for inline assembly. public static final int INVALID_ID = -1; - public LLVMSymbol(String name, int bitcodeID, int symbolIndex, boolean exported) { + public LLVMSymbol(String name, int bitcodeID, int symbolIndex, boolean exported, boolean externalWeak) { this.name = name; this.moduleId = bitcodeID; this.symbolIndex = symbolIndex; this.exported = exported; + this.externalWeak = externalWeak; } public final String getName() { @@ -69,6 +71,10 @@ public final boolean isExported() { return exported; } + public final boolean isExternalWeak() { + return externalWeak; + } + /** * Get the unique index of the symbol. The index is assigned during parsing. Symbols that are * not created from parsing or that are alias have the value of -1. diff --git a/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/global/LLVMGlobal.java b/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/global/LLVMGlobal.java index 2543eb09db6e..b2bb87095086 100644 --- a/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/global/LLVMGlobal.java +++ b/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/global/LLVMGlobal.java @@ -51,22 +51,22 @@ public final class LLVMGlobal extends LLVMSymbol { @CompilationFinal private boolean interopTypeCached; @CompilationFinal private LLVMInteropType interopType; - public static LLVMGlobal create(String name, PointerType type, LLVMSourceSymbol sourceSymbol, boolean readOnly, int index, int id, boolean exported) { + public static LLVMGlobal create(String name, PointerType type, LLVMSourceSymbol sourceSymbol, boolean readOnly, int index, int id, boolean exported, boolean externalWeak) { if (index < 0) { throw new AssertionError("Invalid index for LLVM global: " + index); } if (id < 0) { throw new AssertionError("Invalid index for LLVM global: " + id); } - return new LLVMGlobal(name, type, sourceSymbol, readOnly, index, id, exported); + return new LLVMGlobal(name, type, sourceSymbol, readOnly, index, id, exported, externalWeak); } public static LLVMGlobal createUnavailable(String name) { - return new LLVMGlobal(name + " (unavailable)", PointerType.VOID, null, true, -1, -1, false); + return new LLVMGlobal(name + " (unavailable)", PointerType.VOID, null, true, -1, -1, false, false); } - private LLVMGlobal(String name, PointerType type, LLVMSourceSymbol sourceSymbol, boolean readOnly, int globalIndex, int moduleId, boolean exported) { - super(name, moduleId, globalIndex, exported); + private LLVMGlobal(String name, PointerType type, LLVMSourceSymbol sourceSymbol, boolean readOnly, int globalIndex, int moduleId, boolean exported, boolean externalWeak) { + super(name, moduleId, globalIndex, exported, externalWeak); this.name = name; this.type = type; this.sourceSymbol = sourceSymbol; diff --git a/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/nodes/intrinsics/interop/LLVMTruffleDecorateFunction.java b/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/nodes/intrinsics/interop/LLVMTruffleDecorateFunction.java index cc07f4da0e90..9bb9ebd3dcb0 100644 --- a/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/nodes/intrinsics/interop/LLVMTruffleDecorateFunction.java +++ b/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/nodes/intrinsics/interop/LLVMTruffleDecorateFunction.java @@ -215,7 +215,7 @@ private Object decorateForeign(Object function, LLVMFunctionDescriptor wrapperFu private static Object registerRoot(String path, FunctionType newFunctionType, DecoratedRoot decoratedRoot) { LLVMIRFunction function = new LLVMIRFunction(LLVMLanguage.createCallTarget(decoratedRoot), null); - LLVMFunction functionDetail = LLVMFunction.create("", function, newFunctionType, LLVMSymbol.INVALID_INDEX, LLVMSymbol.INVALID_INDEX, false, path); + LLVMFunction functionDetail = LLVMFunction.create("", function, newFunctionType, LLVMSymbol.INVALID_INDEX, LLVMSymbol.INVALID_INDEX, false, path, false); LLVMFunctionDescriptor wrappedFunction = new LLVMFunctionDescriptor(functionDetail, new LLVMFunctionCode(functionDetail)); return LLVMManagedPointer.create(wrappedFunction); } diff --git a/sulong/projects/com.oracle.truffle.llvm/src/com/oracle/truffle/llvm/ParserDriver.java b/sulong/projects/com.oracle.truffle.llvm/src/com/oracle/truffle/llvm/ParserDriver.java index 531958315641..bca29828234e 100644 --- a/sulong/projects/com.oracle.truffle.llvm/src/com/oracle/truffle/llvm/ParserDriver.java +++ b/sulong/projects/com.oracle.truffle.llvm/src/com/oracle/truffle/llvm/ParserDriver.java @@ -312,7 +312,7 @@ private static void createNewFunction(LLVMScope scope, String originalName, LLVM String.format("The symbol %s could not be imported because the symbol %s was not found in library %s", external.getName(), originalName, lib)); } LLVMFunction newFunction = LLVMFunction.create(name, originalSymbol.getFunction(), originalSymbol.getType(), - parserResult.getRuntime().getBitcodeID(), external.getIndex(), external.isExported(), parserResult.getRuntime().getFile().getPath()); + parserResult.getRuntime().getBitcodeID(), external.getIndex(), external.isExported(), parserResult.getRuntime().getFile().getPath(), external.isExternalWeak()); LLVMScope fileScope = parserResult.getRuntime().getFileScope(); fileScope.register(newFunction); it.remove(); @@ -485,14 +485,14 @@ private static void addExternalSymbolsToScopes(LLVMParserResult parserResult) { for (FunctionSymbol function : parserResult.getExternalFunctions()) { if (!fileScope.contains(function.getName())) { fileScope.register(LLVMFunction.create(function.getName(), new LLVMFunctionCode.UnresolvedFunction(), function.getType(), parserResult.getRuntime().getBitcodeID(), - function.getIndex(), false, parserResult.getRuntime().getFile().getPath())); + function.getIndex(), false, parserResult.getRuntime().getFile().getPath(), function.isExternalWeak())); } } for (GlobalVariable global : parserResult.getExternalGlobals()) { if (!fileScope.contains(global.getName())) { fileScope.register( LLVMGlobal.create(global.getName(), global.getType(), global.getSourceSymbol(), global.isReadOnly(), global.getIndex(), parserResult.getRuntime().getBitcodeID(), - false)); + false, global.isExternalWeak())); } } } diff --git a/sulong/projects/com.oracle.truffle.llvm/src/com/oracle/truffle/llvm/initialization/AllocExternalSymbolNode.java b/sulong/projects/com.oracle.truffle.llvm/src/com/oracle/truffle/llvm/initialization/AllocExternalSymbolNode.java index 402f729c31dd..0872f0786935 100644 --- a/sulong/projects/com.oracle.truffle.llvm/src/com/oracle/truffle/llvm/initialization/AllocExternalSymbolNode.java +++ b/sulong/projects/com.oracle.truffle.llvm/src/com/oracle/truffle/llvm/initialization/AllocExternalSymbolNode.java @@ -197,6 +197,16 @@ abstract static class AllocExternalGlobalNode extends AllocExistingGlobalSymbols super(symbol); } + @Specialization(guards = {"localScope.get(symbol.getName()) == null", "globalScope.get(symbol.getName()) == null", + "symbol.isGlobalVariable()", "symbol.isExternalWeak()"}) + LLVMPointer allocateExternalWeakGlobal(@SuppressWarnings("unused") LLVMLocalScope localScope, + @SuppressWarnings("unused") LLVMScope globalScope, + @SuppressWarnings("unused") LLVMIntrinsicProvider intrinsicProvider, + @SuppressWarnings("unused") NativeContextExtension nativeContextExtension, + @SuppressWarnings("unused") LLVMContext context) { + return LLVMNativePointer.createNull(); + } + @TruffleBoundary @Specialization(guards = {"localScope.get(symbol.getName()) == null", "globalScope.get(symbol.getName()) == null", "!intrinsicProvider.isIntrinsified(symbol.getName())", "nativeContextExtension != null", @@ -229,6 +239,16 @@ abstract static class AllocExternalFunctionNode extends AllocExistingGlobalSymbo this.nodeFactory = nodeFactory; } + @Specialization(guards = {"localScope.get(symbol.getName()) == null", "globalScope.get(symbol.getName()) == null", + "symbol.isFunction()", "symbol.isExternalWeak()"}) + LLVMPointer allocateExternalWeakFunction(@SuppressWarnings("unused") LLVMLocalScope localScope, + @SuppressWarnings("unused") LLVMScope globalScope, + @SuppressWarnings("unused") LLVMIntrinsicProvider intrinsicProvider, + @SuppressWarnings("unused") NativeContextExtension nativeContextExtension, + @SuppressWarnings("unused") LLVMContext context) { + return LLVMNativePointer.createNull(); + } + @TruffleBoundary @Specialization(guards = {"intrinsicProvider != null", "localScope.get(symbol.getName()) == null", "globalScope.get(symbol.getName()) == null", "intrinsicProvider.isIntrinsified(symbol.getName())", "symbol.isFunction()"}) From c4b61faf8bc9b857cf79dfc23d51ca5b2c8e74e8 Mon Sep 17 00:00:00 2001 From: Paley Li Date: Fri, 12 Feb 2021 12:03:08 +0100 Subject: [PATCH 2/5] Sulong: add test for external weak function. Copyright, and formatting. --- .../truffle/llvm/parser/LLVMParser.java | 2 +- .../llvm/parser/model/GlobalSymbol.java | 2 +- .../model/functions/FunctionDeclaration.java | 2 +- .../model/functions/FunctionDefinition.java | 2 +- .../symbols/globals/GlobalValueSymbol.java | 2 +- .../truffle/llvm/runtime/LLVMAlias.java | 2 +- .../truffle/llvm/runtime/LLVMSymbol.java | 2 +- .../llvm/runtime/global/LLVMGlobal.java | 2 +- .../interop/LLVMTruffleDecorateFunction.java | 2 +- .../AllocExternalSymbolNode.java | 2 +- .../c/externalweak.c | 42 +++++++++++++++++++ 11 files changed, 52 insertions(+), 10 deletions(-) create mode 100644 sulong/tests/com.oracle.truffle.llvm.tests.sulong.native/c/externalweak.c diff --git a/sulong/projects/com.oracle.truffle.llvm.parser/src/com/oracle/truffle/llvm/parser/LLVMParser.java b/sulong/projects/com.oracle.truffle.llvm.parser/src/com/oracle/truffle/llvm/parser/LLVMParser.java index a5051e6f86e0..a885704d12c2 100644 --- a/sulong/projects/com.oracle.truffle.llvm.parser/src/com/oracle/truffle/llvm/parser/LLVMParser.java +++ b/sulong/projects/com.oracle.truffle.llvm.parser/src/com/oracle/truffle/llvm/parser/LLVMParser.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2020, Oracle and/or its affiliates. + * Copyright (c) 2016, 2021, Oracle and/or its affiliates. * * All rights reserved. * diff --git a/sulong/projects/com.oracle.truffle.llvm.parser/src/com/oracle/truffle/llvm/parser/model/GlobalSymbol.java b/sulong/projects/com.oracle.truffle.llvm.parser/src/com/oracle/truffle/llvm/parser/model/GlobalSymbol.java index 7c41ff5f7d8c..df0af4841709 100644 --- a/sulong/projects/com.oracle.truffle.llvm.parser/src/com/oracle/truffle/llvm/parser/model/GlobalSymbol.java +++ b/sulong/projects/com.oracle.truffle.llvm.parser/src/com/oracle/truffle/llvm/parser/model/GlobalSymbol.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2020, Oracle and/or its affiliates. + * Copyright (c) 2016, 2021, Oracle and/or its affiliates. * * All rights reserved. * diff --git a/sulong/projects/com.oracle.truffle.llvm.parser/src/com/oracle/truffle/llvm/parser/model/functions/FunctionDeclaration.java b/sulong/projects/com.oracle.truffle.llvm.parser/src/com/oracle/truffle/llvm/parser/model/functions/FunctionDeclaration.java index 68170a0e7fad..605459d693e7 100644 --- a/sulong/projects/com.oracle.truffle.llvm.parser/src/com/oracle/truffle/llvm/parser/model/functions/FunctionDeclaration.java +++ b/sulong/projects/com.oracle.truffle.llvm.parser/src/com/oracle/truffle/llvm/parser/model/functions/FunctionDeclaration.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2020, Oracle and/or its affiliates. + * Copyright (c) 2016, 2021, Oracle and/or its affiliates. * * All rights reserved. * diff --git a/sulong/projects/com.oracle.truffle.llvm.parser/src/com/oracle/truffle/llvm/parser/model/functions/FunctionDefinition.java b/sulong/projects/com.oracle.truffle.llvm.parser/src/com/oracle/truffle/llvm/parser/model/functions/FunctionDefinition.java index fbfb2ecc8841..3ac0d80a3caa 100644 --- a/sulong/projects/com.oracle.truffle.llvm.parser/src/com/oracle/truffle/llvm/parser/model/functions/FunctionDefinition.java +++ b/sulong/projects/com.oracle.truffle.llvm.parser/src/com/oracle/truffle/llvm/parser/model/functions/FunctionDefinition.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2020, Oracle and/or its affiliates. + * Copyright (c) 2016, 2021, Oracle and/or its affiliates. * * All rights reserved. * diff --git a/sulong/projects/com.oracle.truffle.llvm.parser/src/com/oracle/truffle/llvm/parser/model/symbols/globals/GlobalValueSymbol.java b/sulong/projects/com.oracle.truffle.llvm.parser/src/com/oracle/truffle/llvm/parser/model/symbols/globals/GlobalValueSymbol.java index 834976196144..4b7d18f0f215 100644 --- a/sulong/projects/com.oracle.truffle.llvm.parser/src/com/oracle/truffle/llvm/parser/model/symbols/globals/GlobalValueSymbol.java +++ b/sulong/projects/com.oracle.truffle.llvm.parser/src/com/oracle/truffle/llvm/parser/model/symbols/globals/GlobalValueSymbol.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2020, Oracle and/or its affiliates. + * Copyright (c) 2016, 2021, Oracle and/or its affiliates. * * All rights reserved. * diff --git a/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/LLVMAlias.java b/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/LLVMAlias.java index 3823998ed14b..428e812c4e2a 100644 --- a/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/LLVMAlias.java +++ b/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/LLVMAlias.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2020, Oracle and/or its affiliates. + * Copyright (c) 2018, 2021, Oracle and/or its affiliates. * * All rights reserved. * diff --git a/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/LLVMSymbol.java b/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/LLVMSymbol.java index 6f97deab943d..c03f8dd45b32 100644 --- a/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/LLVMSymbol.java +++ b/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/LLVMSymbol.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2020, Oracle and/or its affiliates. + * Copyright (c) 2018, 2021, Oracle and/or its affiliates. * * All rights reserved. * diff --git a/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/global/LLVMGlobal.java b/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/global/LLVMGlobal.java index b2bb87095086..40082c5bad6e 100644 --- a/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/global/LLVMGlobal.java +++ b/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/global/LLVMGlobal.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2020, Oracle and/or its affiliates. + * Copyright (c) 2016, 2021, Oracle and/or its affiliates. * * All rights reserved. * diff --git a/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/nodes/intrinsics/interop/LLVMTruffleDecorateFunction.java b/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/nodes/intrinsics/interop/LLVMTruffleDecorateFunction.java index 9bb9ebd3dcb0..c5ed2141d48b 100644 --- a/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/nodes/intrinsics/interop/LLVMTruffleDecorateFunction.java +++ b/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/nodes/intrinsics/interop/LLVMTruffleDecorateFunction.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2020, Oracle and/or its affiliates. + * Copyright (c) 2016, 2021, Oracle and/or its affiliates. * * All rights reserved. * diff --git a/sulong/projects/com.oracle.truffle.llvm/src/com/oracle/truffle/llvm/initialization/AllocExternalSymbolNode.java b/sulong/projects/com.oracle.truffle.llvm/src/com/oracle/truffle/llvm/initialization/AllocExternalSymbolNode.java index 0872f0786935..db20c6ff8548 100644 --- a/sulong/projects/com.oracle.truffle.llvm/src/com/oracle/truffle/llvm/initialization/AllocExternalSymbolNode.java +++ b/sulong/projects/com.oracle.truffle.llvm/src/com/oracle/truffle/llvm/initialization/AllocExternalSymbolNode.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Oracle and/or its affiliates. + * Copyright (c) 2020, 2021, Oracle and/or its affiliates. * * All rights reserved. * diff --git a/sulong/tests/com.oracle.truffle.llvm.tests.sulong.native/c/externalweak.c b/sulong/tests/com.oracle.truffle.llvm.tests.sulong.native/c/externalweak.c new file mode 100644 index 000000000000..3bb6064d5312 --- /dev/null +++ b/sulong/tests/com.oracle.truffle.llvm.tests.sulong.native/c/externalweak.c @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2021, Oracle and/or its affiliates. + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +__attribute__((weak)) int foo(); + +int main() { + if (foo) { + printf("External weak function is defined!\n"); + } else { + printf("External weak function is NOT defined!\n"); + } + return 0; +} \ No newline at end of file From f06df5aebc24a951acba9c5a274bb0a7f46fcdbb Mon Sep 17 00:00:00 2001 From: Paley Li Date: Tue, 16 Feb 2021 09:28:40 +0100 Subject: [PATCH 3/5] Sulong: test only defined in linux. --- .../c/externalweak.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sulong/tests/com.oracle.truffle.llvm.tests.sulong.native/c/externalweak.c b/sulong/tests/com.oracle.truffle.llvm.tests.sulong.native/c/externalweak.c index 3bb6064d5312..bc7a5bad3997 100644 --- a/sulong/tests/com.oracle.truffle.llvm.tests.sulong.native/c/externalweak.c +++ b/sulong/tests/com.oracle.truffle.llvm.tests.sulong.native/c/externalweak.c @@ -33,10 +33,12 @@ __attribute__((weak)) int foo(); int main() { +#ifdef __linux__ if (foo) { printf("External weak function is defined!\n"); } else { printf("External weak function is NOT defined!\n"); } +#endif return 0; -} \ No newline at end of file +} From d4964d0492d5b415aca51b6471bc0c2c078a3d37 Mon Sep 17 00:00:00 2001 From: Paley Li Date: Fri, 19 Feb 2021 10:26:35 +0100 Subject: [PATCH 4/5] Sulong: fix test for darwin. --- .../c/externalweak.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sulong/tests/com.oracle.truffle.llvm.tests.sulong.native/c/externalweak.c b/sulong/tests/com.oracle.truffle.llvm.tests.sulong.native/c/externalweak.c index bc7a5bad3997..d4ceb388cb37 100644 --- a/sulong/tests/com.oracle.truffle.llvm.tests.sulong.native/c/externalweak.c +++ b/sulong/tests/com.oracle.truffle.llvm.tests.sulong.native/c/externalweak.c @@ -30,15 +30,17 @@ #include +#ifdef __linux__ __attribute__((weak)) int foo(); +#else +void *foo = NULL; //No weak external support for Darwin. This will pretend to be the same. +#endif int main() { -#ifdef __linux__ if (foo) { printf("External weak function is defined!\n"); } else { printf("External weak function is NOT defined!\n"); } -#endif return 0; } From 2a2a73a6afb69df16796efa96b240cb638374643 Mon Sep 17 00:00:00 2001 From: Paley Li Date: Tue, 23 Feb 2021 08:59:42 +0100 Subject: [PATCH 5/5] Sulong: add tests for weak external global variable. --- .../c/externalweak.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/sulong/tests/com.oracle.truffle.llvm.tests.sulong.native/c/externalweak.c b/sulong/tests/com.oracle.truffle.llvm.tests.sulong.native/c/externalweak.c index d4ceb388cb37..80caa2ae5239 100644 --- a/sulong/tests/com.oracle.truffle.llvm.tests.sulong.native/c/externalweak.c +++ b/sulong/tests/com.oracle.truffle.llvm.tests.sulong.native/c/externalweak.c @@ -32,8 +32,11 @@ #ifdef __linux__ __attribute__((weak)) int foo(); +__attribute__((weak)) extern int bar; +#define BAR_ADDR (&bar) #else void *foo = NULL; //No weak external support for Darwin. This will pretend to be the same. +#define BAR_ADDR NULL #endif int main() { @@ -42,5 +45,11 @@ int main() { } else { printf("External weak function is NOT defined!\n"); } + + if (BAR_ADDR) { + printf("External weak global is defined!\n"); + } else { + printf("External weak global is NOT defined!\n"); + } return 0; }