Skip to content

Commit 707588c

Browse files
committed
[SR-648] ELF static binary fixes
- Revert the use of SWIFT_RUNTIME_EXPORT in ImageInspectionELF.cpp and fix the unittests by explicitly adding the file to the list - Revert the change of section data names
1 parent f6866e7 commit 707588c

File tree

5 files changed

+35
-22
lines changed

5 files changed

+35
-22
lines changed

stdlib/public/runtime/ImageInspectionELF.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#if defined(__ELF__) || defined(__ANDROID__)
2020

2121
#include "ImageInspection.h"
22-
#include "../SwiftShims/Visibility.h"
2322
#include <elf.h>
2423
#include <link.h>
2524
#include <dlfcn.h>
@@ -30,11 +29,11 @@ using namespace swift;
3029
/// The symbol name in the image that identifies the beginning of the
3130
/// protocol conformances table.
3231
static const char ProtocolConformancesSymbol[] =
33-
"__swift2_protocol_conformances_start";
32+
".swift2_protocol_conformances_start";
3433
/// The symbol name in the image that identifies the beginning of the
3534
/// type metadata record table.
3635
static const char TypeMetadataRecordsSymbol[] =
37-
"__swift2_type_metadata_start";
36+
".swift2_type_metadata_start";
3837

3938
/// Context arguments passed down from dl_iterate_phdr to its callback.
4039
struct InspectArgs {
@@ -79,7 +78,6 @@ static int iteratePHDRCallback(struct dl_phdr_info *info,
7978
return 0;
8079
}
8180

82-
SWIFT_RUNTIME_EXPORT
8381
void swift::initializeProtocolConformanceLookup() {
8482
// Search the loaded dls. This only searches the already
8583
// loaded ones.
@@ -92,7 +90,6 @@ void swift::initializeProtocolConformanceLookup() {
9290
dl_iterate_phdr(iteratePHDRCallback, &ProtocolConformanceArgs);
9391
}
9492

95-
SWIFT_RUNTIME_EXPORT
9693
void swift::initializeTypeMetadataRecordLookup() {
9794
InspectArgs TypeMetadataRecordArgs = {
9895
TypeMetadataRecordsSymbol,
@@ -101,7 +98,6 @@ void swift::initializeTypeMetadataRecordLookup() {
10198
dl_iterate_phdr(iteratePHDRCallback, &TypeMetadataRecordArgs);
10299
}
103100

104-
SWIFT_RUNTIME_EXPORT
105101
int swift::lookupSymbol(const void *address, SymbolInfo *info) {
106102
Dl_info dlinfo;
107103
if (dladdr(address, &dlinfo) == 0) {

stdlib/public/runtime/ImageInspectionStatic.cpp

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,42 @@
1515
//===----------------------------------------------------------------------===//
1616

1717
#include "ImageInspection.h"
18+
#include <cstring>
1819

1920
// Currently only tested on linux but should work for any ELF platform
2021
#if defined(__ELF__) && defined(__linux__)
2122

22-
// These are defined in swift_sections.S
23-
// Used in swift_sections.S to mark the start of a section
23+
// These are defined in swift_sections.S to mark the start of a section with the
24+
// length of the data followed immediately by the section data
25+
struct alignas(uint64_t) Section;
26+
extern const Section protocolConformancesStart asm(".swift2_protocol_conformances_start");
27+
extern const Section typeMetadataStart asm(".swift2_type_metadata_start");
28+
2429
struct SectionInfo {
2530
uint64_t size;
26-
const uint8_t data[0];
31+
const char *data;
2732
};
28-
extern const SectionInfo __swift2_protocol_conformances_start;
29-
extern const SectionInfo __swift2_type_metadata_start;
3033

34+
static SectionInfo
35+
getSectionInfo(const Section *section) {
36+
SectionInfo info;
37+
memcpy(&info.size, section, sizeof(uint64_t));
38+
info.data = reinterpret_cast<const char *>(section) + sizeof(uint64_t);
39+
return info;
40+
}
3141

3242
void
3343
swift::initializeProtocolConformanceLookup() {
34-
addImageProtocolConformanceBlockCallback(
35-
__swift2_protocol_conformances_start.data,
36-
__swift2_protocol_conformances_start.size);
44+
auto protocolConformances = getSectionInfo(&protocolConformancesStart);
45+
addImageProtocolConformanceBlockCallback(protocolConformances.data,
46+
protocolConformances.size);
3747
}
3848

3949
void
4050
swift::initializeTypeMetadataRecordLookup() {
41-
addImageTypeMetadataRecordBlockCallback(
42-
__swift2_type_metadata_start.data,
43-
__swift2_type_metadata_start.size);
51+
auto typeMetadata = getSectionInfo(&typeMetadataStart);
52+
addImageTypeMetadataRecordBlockCallback(typeMetadata.data,
53+
typeMetadata.size);
4454
}
4555

4656
// This is called from Errors.cpp when dumping a stack trace entry.

stdlib/public/runtime/swift_sections.S

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@
3131
.p2align 3
3232

3333
#if defined(SWIFT_BEGIN)
34-
.globl __\()\name\()_start
35-
.protected __\()\name\()_start
36-
__\()\name\()_start:
34+
.globl .\()\name\()_start
35+
.protected .\()\name\()_start
36+
.\()\name\()_start:
3737
#if defined(__BIG_ENDIAN__)
3838
.long 0
39-
.long .\()\name\()_end - __\()\name\()_start - 8
39+
.long .\()\name\()_end - .\()\name\()_start - 8
4040
#else
41-
.long .\()\name\()_end - __\()\name\()_start - 8
41+
.long .\()\name\()_end - .\()\name\()_start - 8
4242
.long 0
4343
#endif
4444
#endif

unittests/runtime/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
if(("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "${SWIFT_PRIMARY_VARIANT_SDK}") AND
22
("${SWIFT_HOST_VARIANT_ARCH}" STREQUAL "${SWIFT_PRIMARY_VARIANT_ARCH}"))
33

4+
if(SWIFT_BUILD_STATIC_STDLIB AND "${SWIFT_HOST_VARIANT_SDK}" STREQUAL "LINUX")
5+
set(swift_runtime_test_extra_sources
6+
"${CMAKE_CURRENT_SOURCE_DIR}/../../stdlib/public/runtime/ImageInspectionELF.cpp")
7+
endif()
8+
49
add_subdirectory(LongTests)
510

611
set(PLATFORM_SOURCES)
@@ -36,6 +41,7 @@ if(("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "${SWIFT_PRIMARY_VARIANT_SDK}") AND
3641
# from the swiftCore dylib, so we need to link to both the runtime archive
3742
# and the stdlib.
3843
$<TARGET_OBJECTS:swiftRuntime${SWIFT_PRIMARY_VARIANT_SUFFIX}>
44+
${swift_runtime_test_extra_sources}
3945
)
4046

4147
# FIXME: cross-compile for all variants.

unittests/runtime/LongTests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ if(("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "${SWIFT_PRIMARY_VARIANT_SDK}") AND
3232
# from the swiftCore dylib, so we need to link to both the runtime archive
3333
# and the stdlib.
3434
$<TARGET_OBJECTS:swiftRuntime${SWIFT_PRIMARY_VARIANT_SUFFIX}>
35+
${swift_runtime_test_extra_sources}
3536
)
3637

3738
# FIXME: cross-compile for all variants.

0 commit comments

Comments
 (0)