Skip to content

Commit da8195d

Browse files
committed
Reduce C symbols from IMPORT_FSTR_DATA to file scope.
1 parent fd45dbe commit da8195d

File tree

5 files changed

+8
-10
lines changed

5 files changed

+8
-10
lines changed

object.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Macros follow the same pattern:
2525
The _LOCAL variant makes the reference ``static constexpr``.
2626

2727
``DECLARE_FSTR_*``
28-
Use this in a header to declare Object reference so it can be used across
28+
Use this in a header to declare an Object reference so it can be used across
2929
translation units.
3030

3131
Created symbols are C++ and adopt any enclosing namespaced.

src/include/FlashString/Object.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,15 @@
9898
*/
9999
#define IMPORT_FSTR_OBJECT(name, ObjectType, file) \
100100
IMPORT_FSTR_DATA(FSTR_DATA_NAME(name), file) \
101-
extern "C" const FSTR::ObjectBase FSTR_DATA_NAME(name); \
101+
extern "C" __attribute__((visibility("hidden"))) const FSTR::ObjectBase FSTR_DATA_NAME(name); \
102102
DEFINE_FSTR_REF(name, ObjectType, FSTR_DATA_NAME(name));
103103

104104
/**
105105
* @brief Like IMPORT_FSTR_OBJECT except reference is declared static constexpr
106106
*/
107107
#define IMPORT_FSTR_OBJECT_LOCAL(name, ObjectType, file) \
108108
IMPORT_FSTR_DATA(FSTR_DATA_NAME(name), file) \
109-
extern "C" const FSTR::ObjectBase FSTR_DATA_NAME(name); \
109+
extern "C" __attribute__((visibility("hidden"))) const FSTR::ObjectBase FSTR_DATA_NAME(name); \
110110
static constexpr DEFINE_FSTR_REF(name, ObjectType, FSTR_DATA_NAME(name));
111111

112112
namespace FSTR

src/include/FlashString/Utility.hpp

-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ template <typename T, typename U> struct argument_type<T(U)> {
8989
#ifdef __WIN32
9090
#define IMPORT_FSTR_DATA(name, file) \
9191
__asm__(".section .rodata\n" \
92-
".global _" STR(name) "\n" \
9392
".def _" STR(name) "; .scl 2; .type 32; .endef\n" \
9493
".align 4\n" \
9594
"_" STR(name) ":\n" \
@@ -104,7 +103,6 @@ template <typename T, typename U> struct argument_type<T(U)> {
104103
#endif
105104
#define IMPORT_FSTR_DATA(name, file) \
106105
__asm__(".section " IROM_SECTION "\n" \
107-
".global " STR(name) "\n" \
108106
".type " STR(name) ", @object\n" \
109107
".align 4\n" STR(name) ":\n" \
110108
".long _" STR(name) "_end - " STR(name) " - 4\n" \

test/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#####################################################################
44

55
ifndef SMING_HOME
6-
$(error SMING_HOME is not set. Please configure it as an environment variable, or in Makefile-user.mk)
6+
$(error SMING_HOME is not set. Please configure it as an environment variable)
77
endif
88

99
# Include application Makefile

utility.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ using :c:func:`IMPORT_FSTR` or :c:func:`IMPORT_FSTR_ARRAY`. For example::
1212
This defines a C++ reference to the data called ``myData`` so it can be referred to using
1313
:c:func:`DECLARE_FSTR` if required.
1414

15-
.. note::
15+
.. attention::
1616

1717
File paths must be absolute or the compiler won't be able to locate it reliably.
1818

@@ -21,11 +21,11 @@ This defines a C++ reference to the data called ``myData`` so it can be referred
2121

2222
.. note::
2323

24-
A corresponding global C symbol will also be defined, based on the provided name,
24+
A corresponding C symbol will also be defined, based on the provided name,
2525
to provide linkage with the imported data.
2626

27-
Such symbols cannot be localised as it requires use of ``extern``, so take care with
28-
naming to avoid the risk of conflicts, especially if used within a Component.
27+
You generally shouldn't have an issue with this as the symbols are restricted to
28+
file scope, but it is something to be aware of.
2929

3030

3131
One use for imported files is to serve content via HTTP, like this::

0 commit comments

Comments
 (0)