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

Fix dragonfly #1224

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 18 additions & 3 deletions Makefile
Expand Up @@ -34,6 +34,11 @@ else
OSTYPE = freebsd
CXX = c++
endif

ifeq ($(UNAME_S),DragonFly)
OSTYPE = dragonfly
CXX = c++
endif
endif

ifdef LTO_PLUGIN
Expand Down Expand Up @@ -142,7 +147,7 @@ ifeq ($(config),release)
AR_FLAGS += --plugin $(LTO_PLUGIN)
endif

ifneq (,$(filter $(OSTYPE),linux freebsd))
ifneq (,$(filter $(OSTYPE),linux freebsd,dragonfly))
LINKER_FLAGS += -fuse-linker-plugin -fuse-ld=gold
endif
endif
Expand Down Expand Up @@ -254,7 +259,9 @@ endif

ifneq ($(OSTYPE),osx)
ifneq ($(OSTYPE),freebsd)
libponyrt.except += src/libponyrt/asio/kqueue.c
ifneq ($(OSTYPE),dragonfly)
libponyrt.except += src/libponyrt/asio/kqueue.c
endif
endif
endif

Expand Down Expand Up @@ -305,6 +312,14 @@ ifeq ($(OSTYPE), freebsd)
llvm.libs += -lpthread
endif

ifeq ($(OSTYPE), dragonfly)
llvm.libs += -lpthread
endif

ifeq ($(OSTYPE), dragonfly)
llvm.ldflags += -L/usr/local/lib
endif

prebuilt := llvm

# Binaries. Defined as
Expand Down Expand Up @@ -333,7 +348,7 @@ libponyrt.tests.include := -I src/common/ -I src/libponyrt/ -isystem lib/gtest/
ponyc.include := -I src/common/ -I src/libponyrt/ $(llvm.include)
libgtest.include := -isystem lib/gtest/

ifneq (,$(filter $(OSTYPE), osx freebsd))
ifneq (,$(filter $(OSTYPE), osx freebsd dragonfly))
libponyrt.include += -I /usr/local/include
endif

Expand Down
5 changes: 4 additions & 1 deletion src/common/platform.h
Expand Up @@ -24,6 +24,8 @@
# define PLATFORM_IS_LINUX
#elif defined(__FreeBSD__)
# define PLATFORM_IS_FREEBSD
#elif defined(__DragonFly__)
# define PLATFORM_IS_DRAGONFLY
#elif defined(_WIN32)
# define PLATFORM_IS_WINDOWS
# if defined(_MSC_VER)
Expand Down Expand Up @@ -91,7 +93,8 @@
# error PLATFORM NOT SUPPORTED!
#endif

#if defined(PLATFORM_IS_MACOSX) || defined(PLATFORM_IS_LINUX) || defined (PLATFORM_IS_FREEBSD)
#if defined(PLATFORM_IS_MACOSX) || defined(PLATFORM_IS_LINUX) || defined (PLATFORM_IS_FREEBSD) || \
defined(PLATFORM_IS_DRAGONFLY)
# define PLATFORM_IS_POSIX_BASED
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/libponyc/codegen/genexe.c
Expand Up @@ -259,7 +259,7 @@ static bool link_exe(compile_t* c, ast_t* program,
ponyint_pool_free_size(dsym_len, dsym_cmd);
}

#elif defined(PLATFORM_IS_LINUX) || defined(PLATFORM_IS_FREEBSD)
#elif defined(PLATFORM_IS_LINUX) || defined(PLATFORM_IS_FREEBSD) || defined(PLATFORM_IS_DRAGONFLY)
const char* file_exe =
suffix_filename(c, c->opt->output, "", c->filename, "");

Expand Down
7 changes: 7 additions & 0 deletions src/libponyc/codegen/genopt.cc
Expand Up @@ -1011,6 +1011,13 @@ bool target_is_linux(char* t)
return triple.isOSLinux();
}

bool target_is_dragonfly(char* t)
{
Triple triple = Triple(t);

return triple.isOSDragonFly();
}

bool target_is_freebsd(char* t)
{
Triple triple = Triple(t);
Expand Down
1 change: 1 addition & 0 deletions src/libponyc/codegen/genopt.h
Expand Up @@ -9,6 +9,7 @@ PONY_EXTERN_C_BEGIN
bool genopt(compile_t* c, bool pony_specific);
bool target_is_linux(char* triple);
bool target_is_freebsd(char* triple);
bool target_is_dragonfly(char* triple);
bool target_is_macosx(char* triple);
bool target_is_windows(char* triple);
bool target_is_posix(char* triple);
Expand Down
1 change: 1 addition & 0 deletions src/libponyc/pkg/buildflagset.c
Expand Up @@ -11,6 +11,7 @@
// Mutually exclusive platform flag groups.
static const char* _os_flags[] =
{
OS_DRAGONFLY_NAME,
OS_FREEBSD_NAME,
OS_LINUX_NAME,
OS_MACOSX_NAME,
Expand Down
4 changes: 3 additions & 1 deletion src/libponyc/pkg/ifdef.c
Expand Up @@ -71,7 +71,9 @@ static void cond_normalise(ast_t** astp)
NODE(TK_IFDEFOR,
NODE(TK_IFDEFFLAG, ID(OS_LINUX_NAME))
NODE(TK_IFDEFFLAG, ID(OS_MACOSX_NAME)))
NODE(TK_IFDEFFLAG, ID(OS_FREEBSD_NAME))));
NODE(TK_IFDEFOR,
NODE(TK_IFDEFFLAG, ID(OS_FREEBSD_NAME))
NODE(TK_IFDEFFLAG, ID(OS_DRAGONFLY_NAME)))));
break;
}

Expand Down
4 changes: 2 additions & 2 deletions src/libponyc/pkg/package.c
Expand Up @@ -21,7 +21,7 @@
#include <unistd.h>
#elif defined(PLATFORM_IS_MACOSX)
#include <mach-o/dyld.h>
#elif defined(PLATFORM_IS_FREEBSD)
#elif defined(PLATFORM_IS_FREEBSD) || defined(PLATFORM_IS_DRAGONFLY)
#include <unistd.h>
#include <sys/types.h>
#include <sys/sysctl.h>
Expand Down Expand Up @@ -585,7 +585,7 @@ static bool add_exec_dir(pass_opt_t* opt)

if(success)
path[r] = '\0';
#elif defined PLATFORM_IS_FREEBSD
#elif defined(PLATFORM_IS_FREEBSD) || defined(PLATFORM_IS_DRAGONFLY)
int mib[4];
mib[0] = CTL_KERN;
mib[1] = KERN_PROC;
Expand Down
6 changes: 6 additions & 0 deletions src/libponyc/pkg/platformfuns.c
Expand Up @@ -11,6 +11,12 @@ bool os_is_target(const char* attribute, bool release, bool* out_is_target, pass
assert(out_is_target != NULL);
assert(options != NULL);

if(!strcmp(attribute, OS_DRAGONFLY_NAME))
{
*out_is_target = target_is_dragonfly(options->triple);
return true;
}

if(!strcmp(attribute, OS_FREEBSD_NAME))
{
*out_is_target = target_is_freebsd(options->triple);
Expand Down
1 change: 1 addition & 0 deletions src/libponyc/pkg/platformfuns.h
Expand Up @@ -7,6 +7,7 @@
PONY_EXTERN_C_BEGIN

// OS names used in platform.pony
#define OS_DRAGONFLY_NAME "dragonfly"
#define OS_FREEBSD_NAME "freebsd"
#define OS_LINUX_NAME "linux"
#define OS_MACOSX_NAME "osx"
Expand Down
2 changes: 1 addition & 1 deletion src/libponyrt/asio/asio.h
Expand Up @@ -7,7 +7,7 @@

#if defined(PLATFORM_IS_LINUX)
# define ASIO_USE_EPOLL
#elif defined(PLATFORM_IS_MACOSX) || defined(PLATFORM_IS_FREEBSD)
#elif defined(PLATFORM_IS_MACOSX) || defined(PLATFORM_IS_FREEBSD) | defined(PLATFORM_IS_DRAGONFLY)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

needs to be || defined(PLATFORM_IS_DRAGONFLY)

# define ASIO_USE_KQUEUE
#elif defined(PLATFORM_IS_WINDOWS)
# define ASIO_USE_IOCP
Expand Down
4 changes: 2 additions & 2 deletions src/libponyrt/asio/kqueue.c
Expand Up @@ -166,7 +166,7 @@ void pony_asio_event_subscribe(asio_event_t* ev)

if(ev->flags & ASIO_TIMER)
{
#ifdef PLATFORM_IS_FREEBSD
#if defined(PLATFORM_IS_FREEBSD) || defined(PLATFORM_IS_DRAGONFLY)
EV_SET(&event[i], (uintptr_t)ev, EVFILT_TIMER, EV_ADD | EV_ONESHOT,
0, ev->nsec / 1000000, ev);
#else
Expand Down Expand Up @@ -209,7 +209,7 @@ void pony_asio_event_setnsec(asio_event_t* ev, uint64_t nsec)
{
ev->nsec = nsec;

#ifdef PLATFORM_IS_FREEBSD
#if defined(PLATFORM_IS_FREEBSD) || defined(PLATFORM_IS_DRAGONFLY)
EV_SET(&event[i], (uintptr_t)ev, EVFILT_TIMER, EV_ADD | EV_ONESHOT,
0, ev->nsec / 1000000, ev);
#else
Expand Down
2 changes: 1 addition & 1 deletion src/libponyrt/lang/directory.c
Expand Up @@ -131,7 +131,7 @@ const char* ponyint_unix_readdir(DIR* dir)

#if defined(PLATFORM_IS_LINUX)
size_t len = strlen(d->d_name);
#elif defined(PLATFORM_IS_FREEBSD) || defined(PLATFORM_IS_MACOSX)
#elif defined(PLATFORM_IS_FREEBSD) || defined(PLATFORM_IS_MACOSX) || defined(PLATFORM_IS_DRAGONFLY)
size_t len = d->d_namlen;
#endif

Expand Down
6 changes: 3 additions & 3 deletions src/libponyrt/lang/socket.c
Expand Up @@ -119,7 +119,7 @@ static struct addrinfo* os_addrinfo_intern(int family, int socktype,
return result;
}

#if defined(PLATFORM_IS_MACOSX) || defined(PLATFORM_IS_FREEBSD)
#if defined(PLATFORM_IS_MACOSX) || defined(PLATFORM_IS_FREEBSD) || defined(PLATFORM_IS_DRAGONFLY)
static int set_nonblocking(int s)
{
int flags = fcntl(s, F_GETFL, 0);
Expand Down Expand Up @@ -446,7 +446,7 @@ static int socket_from_addrinfo(struct addrinfo* p, bool reuse)
(const char*)&reuseaddr, sizeof(int));
}

#if defined(PLATFORM_IS_MACOSX) || defined(PLATFORM_IS_FREEBSD)
#if defined(PLATFORM_IS_MACOSX) || defined(PLATFORM_IS_FREEBSD) || defined(PLATFORM_IS_DRAGONFLY)
r |= set_nonblocking(fd);
#endif

Expand Down Expand Up @@ -986,7 +986,7 @@ void pony_os_keepalive(int fd, int secs)
if(on == 0)
return;

#if defined(PLATFORM_IS_LINUX) || defined(PLATFORM_IS_FREEBSD)
#if defined(PLATFORM_IS_LINUX) || defined(PLATFORM_IS_FREEBSD) || defined(PLATFORM_IS_DRAGONFLY)
int probes = secs / 2;
setsockopt(s, IPPROTO_TCP, TCP_KEEPCNT, &probes, sizeof(int));

Expand Down
3 changes: 3 additions & 0 deletions src/libponyrt/mem/alloc.c
Expand Up @@ -29,6 +29,9 @@ void* ponyint_virt_alloc(size_t bytes)
#elif defined(PLATFORM_IS_FREEBSD)
p = mmap(0, bytes, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANON | MAP_ALIGNED_SUPER, -1, 0);
#elif defined(PLATFORM_IS_DRAGONFLY)
p = mmap(0, bytes, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANON, -1, 0);
#endif

if(p == MAP_FAILED)
Expand Down
2 changes: 1 addition & 1 deletion src/libponyrt/platform/threads.c
Expand Up @@ -3,7 +3,7 @@
#endif
#include <platform.h>

#if defined(PLATFORM_IS_LINUX) || defined(PLATFORM_IS_FREEBSD)
#if defined(PLATFORM_IS_LINUX) || defined(PLATFORM_IS_FREEBSD) || defined(PLATFORM_IS_DRAGONFLY)
#include <sched.h>
#include <sys/time.h>
#include <sys/resource.h>
Expand Down
10 changes: 5 additions & 5 deletions src/libponyrt/sched/cpu.c
Expand Up @@ -3,7 +3,7 @@
#endif
#include <platform.h>

#if defined(PLATFORM_IS_LINUX) || defined(PLATFORM_IS_FREEBSD)
#if defined(PLATFORM_IS_LINUX) || defined(PLATFORM_IS_FREEBSD) || defined(PLATFORM_IS_DRAGONFLY)
#include <sched.h>
#include <stdlib.h>
#include <unistd.h>
Expand All @@ -24,7 +24,7 @@ static uint32_t avail_cpu_count;
static uint32_t* avail_cpu_list;
#endif

#if defined(PLATFORM_IS_MACOSX) || defined(PLATFORM_IS_FREEBSD)
#if defined(PLATFORM_IS_MACOSX) || defined(PLATFORM_IS_FREEBSD) || defined(PLATFORM_IS_DRAGONFLY)

#include <sys/types.h>
#include <sys/sysctl.h>
Expand Down Expand Up @@ -133,7 +133,7 @@ void ponyint_cpu_init()
i = cpu_add_mask_to_list(i, &hw_cpus);
i = cpu_add_mask_to_list(i, &ht_cpus);
}
#elif defined(PLATFORM_IS_FREEBSD)
#elif defined(PLATFORM_IS_FREEBSD) || defined(PLATFORM_IS_DRAGONFLY)
hw_cpu_count = property("hw.ncpu");
#elif defined(PLATFORM_IS_MACOSX)
hw_cpu_count = property("hw.physicalcpu");
Expand Down Expand Up @@ -218,7 +218,7 @@ uint32_t ponyint_cpu_assign(uint32_t count, scheduler_t* scheduler,
avail_cpu_list = NULL;

return asio_cpu;
#elif defined(PLATFORM_IS_FREEBSD)
#elif defined(PLATFORM_IS_FREEBSD) || defined(PLATFORM_IS_DRAGONFLY)
// FreeBSD does not currently do thread pinning, as we can't yet determine
// which cores are hyperthreads.

Expand Down Expand Up @@ -256,7 +256,7 @@ void ponyint_cpu_affinity(uint32_t cpu)

#if defined(PLATFORM_IS_LINUX)
// Affinity is handled when spawning the thread.
#elif defined(PLATFORM_IS_FREEBSD)
#elif defined(PLATFORM_IS_FREEBSD) || defined(PLATFORM_IS_DRAGONFLY)
// No pinning, since we cannot yet determine hyperthreads vs physical cores.
#elif defined(PLATFORM_IS_MACOSX)
thread_affinity_policy_data_t policy;
Expand Down