Skip to content

Commit

Permalink
Do not publish internal symbols to header files
Browse files Browse the repository at this point in the history
  • Loading branch information
loicottet committed Apr 4, 2022
1 parent 5320865 commit 03e26e9
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
Expand Down Expand Up @@ -53,7 +53,7 @@ private VmLocatorSymbol() {
throw new IllegalStateException("No instance allowed");
}

@CEntryPoint(name = "vmLocatorSymbol")
@CEntryPoint(name = "graal_vm_locator_symbol", publishAs = CEntryPoint.Publish.SymbolOnly)
@SuppressWarnings("unused")
private static void vmLocatorSymbol(IsolateThread thread) {
}
Expand Down
11 changes: 11 additions & 0 deletions sdk/src/org.graalvm.nativeimage/snapshot.sigtest
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ innr public abstract interface static !annotation IsolateContext
innr public abstract interface static !annotation IsolateThreadContext
innr public abstract interface static ExceptionHandler
innr public final static !enum Builtin
innr public final static !enum Publish
innr public final static AlwaysIncluded
innr public final static FatalExceptionHandler
innr public final static NotIncludedAutomatically
Expand All @@ -520,6 +521,7 @@ meth public abstract !hasdefault java.lang.Class<? extends org.graalvm.nativeima
meth public abstract !hasdefault java.lang.String name()
meth public abstract !hasdefault java.lang.String[] documentation()
meth public abstract !hasdefault org.graalvm.nativeimage.c.function.CEntryPoint$Builtin builtin()
meth public abstract !hasdefault org.graalvm.nativeimage.c.function.CEntryPoint$Publish publishAs()

CLSS public final static org.graalvm.nativeimage.c.function.CEntryPoint$AlwaysIncluded
outer org.graalvm.nativeimage.c.function.CEntryPoint
Expand Down Expand Up @@ -566,6 +568,15 @@ intf java.util.function.BooleanSupplier
meth public boolean getAsBoolean()
supr java.lang.Object

CLSS public final static !enum org.graalvm.nativeimage.c.function.CEntryPoint$Publish
outer org.graalvm.nativeimage.c.function.CEntryPoint
fld public final static org.graalvm.nativeimage.c.function.CEntryPoint$Publish NotPublished
fld public final static org.graalvm.nativeimage.c.function.CEntryPoint$Publish SymbolOnly
fld public final static org.graalvm.nativeimage.c.function.CEntryPoint$Publish SymbolAndHeader
meth public static org.graalvm.nativeimage.c.function.CEntryPoint$Publish valueOf(java.lang.String)
meth public static org.graalvm.nativeimage.c.function.CEntryPoint$Publish[] values()
supr java.lang.Enum<org.graalvm.nativeimage.c.function.CEntryPoint$Publish>

CLSS public final org.graalvm.nativeimage.c.function.CEntryPointLiteral<%0 extends org.graalvm.nativeimage.c.function.CFunctionPointer>
meth public !varargs static <%0 extends org.graalvm.nativeimage.c.function.CFunctionPointer> org.graalvm.nativeimage.c.function.CEntryPointLiteral<{%%0}> create(java.lang.Class<?>,java.lang.String,java.lang.Class<?>[])
meth public {org.graalvm.nativeimage.c.function.CEntryPointLiteral%0} getFunctionPointer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,32 @@ public boolean getAsBoolean() {
}
}

/**
* @since 22.0
*/
enum Publish {
/**
* Do not publish the entry point method.
*/
NotPublished,
/**
* Create a symbol for the entry point method in the native image.
*/
SymbolOnly,
/**
* Create a symbol for the entry point method in the native image, and if building a shared
* library image, also include a C declaration in the generated C header file.
*/
SymbolAndHeader,
}

/**
* Whether the entry point is part of the symbols and header files produced by Native Image.
*
* @since 22.0
*/
Publish publishAs() default Publish.SymbolAndHeader;

/**
* The built-in methods which can be {@linkplain #builtin() aliased}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,21 +206,39 @@ final class NoEpilogue implements Epilogue {
*/
Class<? extends Epilogue> epilogue() default LeaveEpilogue.class;

/**
* @deprecated Use {@link org.graalvm.nativeimage.c.function.CEntryPoint.Publish}.
*/
@Deprecated
enum Publish {
/**
* Do not publish the entry point method.
*/
NotPublished,
NotPublished(CEntryPoint.Publish.NotPublished),
/**
* Create a symbol for the entry point method in the native image.
*/
SymbolOnly,
SymbolOnly(CEntryPoint.Publish.SymbolOnly),
/**
* Create a symbol for the entry point method in the native image, and if building a shared
* library image, also include a C declaration in the generated C header file.
*/
SymbolAndHeader,
SymbolAndHeader(CEntryPoint.Publish.SymbolAndHeader);

private final CEntryPoint.Publish conversion;

Publish(CEntryPoint.Publish conversion) {
this.conversion = conversion;
}

public CEntryPoint.Publish convert() {
return conversion;
}
}

/**
* @deprecated Use {@link org.graalvm.nativeimage.c.function.CEntryPoint#publishAs()}.
*/
@Deprecated
Publish publishAs() default Publish.SymbolAndHeader;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@

import org.graalvm.nativeimage.c.function.CEntryPoint;
import org.graalvm.nativeimage.c.function.CEntryPoint.Builtin;
import org.graalvm.nativeimage.c.function.CEntryPoint.Publish;

import com.oracle.svm.core.c.function.CEntryPointOptions;
import com.oracle.svm.core.c.function.CEntryPointOptions.DefaultNameTransformation;
import com.oracle.svm.core.c.function.CEntryPointOptions.Publish;
import com.oracle.svm.core.c.function.CEntryPointSetup;
import com.oracle.svm.core.util.UserError;
import com.oracle.svm.core.util.VMError;
import com.oracle.svm.hosted.image.NativeImage;

Expand Down Expand Up @@ -97,13 +98,21 @@ private static CEntryPointData create(CEntryPoint annotation, CEntryPointOptions
Class<?> prologueBailout = DEFAULT_PROLOGUE_BAILOUT;
Class<?> epilogue = DEFAULT_EPILOGUE;
Class<?> exceptionHandler = annotation.exceptionHandler();
Publish publishAs = Publish.SymbolAndHeader;
Publish publishAs = annotation.publishAs();
if (options != null) {
nameTransformation = options.nameTransformation();
prologue = options.prologue();
prologueBailout = options.prologueBailout();
epilogue = options.epilogue();
publishAs = options.publishAs();
CEntryPointOptions.Publish cEntryPointOptionsPublishAs = options.publishAs();
if (cEntryPointOptionsPublishAs != CEntryPointOptions.Publish.SymbolAndHeader) {
if (publishAs != Publish.SymbolAndHeader) {
throw UserError.abort(
"The 'publishAs' attribute for entry point method %s is specified both in 'CEntryPoint' and 'CEntryPointOptions' annotations. Remove the deprecated 'CEntryPointOptions#publishAs' attribute.",
alternativeNameSupplier.get());
}
publishAs = options.publishAs().convert();
}
}
return create(annotatedName, alternativeNameSupplier, nameTransformation, documentation, builtin, prologue, prologueBailout, epilogue, exceptionHandler, publishAs);
}
Expand Down

0 comments on commit 03e26e9

Please sign in to comment.