Skip to content

SwiftDemangle: build on non-Darwin targets #12705

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

Merged
merged 1 commit into from
Nov 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cmake/modules/AddSwift.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,8 @@ function(_add_swift_library_single target name)
# On platforms that use ELF binaries we add markers for metadata sections in
# the shared libraries using these object files. This wouldn't be necessary
# if the link was done by the swift binary: rdar://problem/19007002
if("${SWIFT_SDK_${SWIFTLIB_SINGLE_SDK}_OBJECT_FORMAT}" STREQUAL "ELF")
if(SWIFTLIB_TARGET_LIBRARY AND
"${SWIFT_SDK_${SWIFTLIB_SINGLE_SDK}_OBJECT_FORMAT}" STREQUAL "ELF")
if("${libkind}" STREQUAL "SHARED")
set(arch_subdir "${SWIFTLIB_DIR}/${SWIFTLIB_SINGLE_SUBDIR}")

Expand Down
4 changes: 1 addition & 3 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ add_subdirectory(PrintAsObjC)
add_subdirectory(RemoteAST)
add_subdirectory(Sema)
add_subdirectory(Serialization)
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
add_subdirectory(SwiftDemangle)
endif()
add_subdirectory(SwiftDemangle)
add_subdirectory(SIL)
add_subdirectory(SILGen)
add_subdirectory(SILOptimizer)
Expand Down
3 changes: 3 additions & 0 deletions lib/SwiftDemangle/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ add_swift_library(swiftDemangle SHARED
SwiftDemangle.cpp
MangleHack.cpp
LINK_LIBRARIES swiftDemangling)
if(NOT APPLE)
target_link_libraries(swiftDemangle PRIVATE bsd)
endif()

swift_install_in_component(compiler
TARGETS swiftDemangle
Expand Down
32 changes: 30 additions & 2 deletions lib/SwiftDemangle/MangleHack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,39 @@
//
//===----------------------------------------------------------------------===//

#include "swift/Strings.h"
#include "swift/SwiftDemangle/MangleHack.h"
#include "swift/Strings.h"
#include <cassert>
#include <cstring>
#include <cstdarg>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#if defined(_WIN32)
static int vasprintf(char **strp, const char *fmt, va_list ap) {
int len = _vscprintf(fmt, ap);
if (len < 0)
return len;
char *buffer = static_cast<char *>(malloc(len + 1));
if (buffer == nullptr)
return -1;
int result = vsprintf(buffer, fmt, ap);
if (result < 0) {
free(buffer);
return -1;
}
*strp = buffer;
return result;
}

static int asprintf(char **strp, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
int result = vasprintf(strp, fmt, args);
va_end(args);
return result;
}
#endif

const char *
_swift_mangleSimpleClass(const char *module, const char *class_) {
Expand Down
3 changes: 3 additions & 0 deletions lib/SwiftDemangle/SwiftDemangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

#include "swift/Demangling/Demangle.h"
#include "swift/SwiftDemangle/SwiftDemangle.h"
#if defined(__linux__) || defined(_WIN32)
#include <bsd/string.h>
#endif

static size_t swift_demangle_getDemangledName_Options(const char *MangledName,
char *OutputBuffer, size_t Length,
Expand Down