Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Factorize REGISTER_* macros and logic for ports and nifs #1172

Merged
merged 1 commit into from
Jun 7, 2024

Conversation

pguyot
Copy link
Collaborator

@pguyot pguyot commented May 28, 2024

esp32, rp2040 and stm32 all use the same logic to use .ctor runtime to register drivers and nifs collections.

Also use the smaller constructor name for nifs of RP2040 on other platforms to maintain compatibility as RP2040 builds have to explicitely list nifs so they are not gc'd. EPS32 is unaffected as enabling of nifs is done through menuconfig.

These changes are made under both the "Apache 2.0" and the "GNU Lesser General
Public License 2.1 or later" license terms (dual license).

SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later

esp32, rp2040 and stm32 all use the same logic to use .ctor runtime to
register drivers and nifs collections.

Also use the smaller constructor name for nifs of RP2040 on other platforms to
maintain compatibility as RP2040 builds have to explicitely list nifs so they
are not gc'd. EPS32 is unaffected as enabling of nifs is done through menuconfig.

Signed-off-by: Paul Guyot <[email protected]>
Copy link
Collaborator

@bettio bettio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks good, but I'm not sure if I understood this:

Also use the smaller constructor name for nifs of RP2040 on other platforms to maintain compatibility as RP2040 builds have to explicitely list nifs so they are not gc'd. EPS32 is unaffected as enabling of nifs is done through menuconfig.

Can you clarify it?

@pguyot
Copy link
Collaborator Author

pguyot commented Jun 6, 2024

Everything looks good, but I'm not sure if I understood this:

Also use the smaller constructor name for nifs of RP2040 on other platforms to maintain compatibility as RP2040 builds have to explicitely list nifs so they are not gc'd. EPS32 is unaffected as enabling of nifs is done through menuconfig.

Can you clarify it?

The three sets of macros (esp32, stm32, rp2040) were identical, except for the name of the constructor for NIFs.

In rp2040_sys.h, line 72:

    __attribute__((constructor)) void NAME##_nif()                          \

In stm_sys.h, line 84

    __attribute__((constructor)) void NAME##register_nif_collection()       \

In esp32_sys.h, line 75

    __attribute__((constructor)) void NAME##register_nif_collection()       \

I chose the name from rp2040_sys.h because it's referred to in CMakeLists.txt with -Wl,-u -Wl,<name>_nif:

    target_link_options(libAtomVM${PLATFORM_LIB_SUFFIX} PUBLIC "SHELL:-Wl,-u -Wl,networkregister_port_driver -Wl,-u -Wl,otp_socket_nif -Wl,-u -Wl,otp_net_nif -Wl,-u -Wl,otp_ssl_nif")
endif()

target_link_options(libAtomVM${PLATFORM_LIB_SUFFIX} PUBLIC "SHELL:-Wl,-u -Wl,gpio_nif -Wl,-u -Wl,otp_crypto_nif")

@bettio bettio merged commit a3f15ad into atomvm:main Jun 7, 2024
85 of 90 checks passed
@pguyot pguyot deleted the w22/refactor-portnif-loading branch June 7, 2024 07:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants