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

Mac support #72

Open
4 of 6 tasks
margnus1 opened this issue Jan 24, 2020 · 0 comments
Open
4 of 6 tasks

Mac support #72

margnus1 opened this issue Jan 24, 2020 · 0 comments

Comments

@margnus1
Copy link
Contributor

margnus1 commented Jan 24, 2020

I create this issue to document and track progress on mac support, since I'm currently out of time to take it further.

Currently, nidhugg can be compiled on mac by installing llvm and boost from homebrew, and then configuring with ./configure --with-llvm=$(brew --prefix llvm) --with-boost=$(brew --prefix boost)

The last issue can be reproduced by trying to run tests/smoke/C-tests/mutex_hard.c on nidhuggc on mac. The LLVM IR produced for this test on mac is:

; ModuleID = 'tests/smoke/C-tests/mutex_hard.c'
source_filename = "tests/smoke/C-tests/mutex_hard.c"
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.13.0"
%struct._opaque_pthread_mutex_t = type { i64, [56 x i8] }
%struct._opaque_pthread_t = type { i64, %struct.__darwin_pthread_handler_rec*, [8176 x i8] }
%struct.__darwin_pthread_handler_rec = type { void (i8*)*, i8*, %struct.__darwin_pthread_handler_rec* }
%struct._opaque_pthread_mutexattr_t = type { i64, [8 x i8] }
%struct._opaque_pthread_attr_t = type { i64, [56 x i8] }
@x = global i32 0, align 4
@m = common global %struct._opaque_pthread_mutex_t zeroinitializer, align 8
; Function Attrs: noinline nounwind optnone ssp uwtable
define i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca [3 x %struct._opaque_pthread_t*], align 16
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store i32 0, i32* %1, align 4
  %5 = call i32 @pthread_mutex_init(%struct._opaque_pthread_mutex_t* @m, %struct._opaque_pthread_mutexattr_t* null)
  store i32 0, i32* %3, align 4
  br label %6
6:                                                ; preds = %18, %0
  %7 = load i32, i32* %3, align 4
  %8 = icmp ult i32 %7, 3
  br i1 %8, label %9, label %21
9:                                                ; preds = %6
  %10 = getelementptr inbounds [3 x %struct._opaque_pthread_t*], [3 x %struct._opaque_pthread_t*]* %2, i64 0, i64 0
  %11 = load i32, i32* %3, align 4
  %12 = zext i32 %11 to i64
  %13 = getelementptr inbounds %struct._opaque_pthread_t*, %struct._opaque_pthread_t** %10, i64 %12
  %14 = load i32, i32* %3, align 4
  %15 = zext i32 %14 to i64
  %16 = inttoptr i64 %15 to i8*
  %17 = call i32 @pthread_create(%struct._opaque_pthread_t** %13, %struct._opaque_pthread_attr_t* null, i8* (i8*)* @t, i8* %16)
  br label %18
18:                                               ; preds = %9
  %19 = load i32, i32* %3, align 4
  %20 = add i32 %19, 1
  store i32 %20, i32* %3, align 4
  br label %6
21:                                               ; preds = %6
  store i32 0, i32* %4, align 4
  br label %22
22:                                               ; preds = %31, %21
  %23 = load i32, i32* %4, align 4
  %24 = icmp ult i32 %23, 3
  br i1 %24, label %25, label %34
25:                                               ; preds = %22
  %26 = load i32, i32* %4, align 4
  %27 = zext i32 %26 to i64
  %28 = getelementptr inbounds [3 x %struct._opaque_pthread_t*], [3 x %struct._opaque_pthread_t*]* %2, i64 0, i64 %27
  %29 = load %struct._opaque_pthread_t*, %struct._opaque_pthread_t** %28, align 8
  %30 = call i32 @"\01_pthread_join"(%struct._opaque_pthread_t* %29, i8** null)
  br label %31
31:                                               ; preds = %25
  %32 = load i32, i32* %4, align 4
  %33 = add i32 %32, 1
  store i32 %33, i32* %4, align 4
  br label %22
34:                                               ; preds = %22
  ret i32 0
}
declare i32 @pthread_mutex_init(%struct._opaque_pthread_mutex_t*, %struct._opaque_pthread_mutexattr_t*) #1
declare !callback !3 i32 @pthread_create(%struct._opaque_pthread_t**, %struct._opaque_pthread_attr_t*, i8* (i8*)*, i8*) #1
; Function Attrs: noinline nounwind optnone ssp uwtable
define internal i8* @t(i8*) #0 {
  %2 = alloca i8*, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i8* %0, i8** %2, align 8
  %6 = load i8*, i8** %2, align 8
  %7 = ptrtoint i8* %6 to i64
  %8 = trunc i64 %7 to i32
  store i32 %8, i32* %3, align 4
  %9 = call i32 @pthread_mutex_lock(%struct._opaque_pthread_mutex_t* @m)
  store i32 1, i32* %4, align 4
  %10 = load i32, i32* %4, align 4
  %11 = atomicrmw add i32* @x, i32 %10 seq_cst
  store i32 %11, i32* %5, align 4
  %12 = load i32, i32* %5, align 4
  %13 = load i32, i32* %3, align 4
  %14 = icmp eq i32 %12, %13
  br i1 %14, label %15, label %17
15:                                               ; preds = %1
  %16 = call i32 @pthread_mutex_unlock(%struct._opaque_pthread_mutex_t* @m)
  br label %17
17:                                               ; preds = %15, %1
  ret i8* null
}

declare i32 @"\01_pthread_join"(%struct._opaque_pthread_t*, i8**) #1
declare i32 @pthread_mutex_lock(%struct._opaque_pthread_mutex_t*) #1
declare i32 @pthread_mutex_unlock(%struct._opaque_pthread_mutex_t*) #1
attributes #0 = { noinline nounwind optnone ssp uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="penryn" "target-features"="+cx16,+cx8,+fxsr,+mmx,+sahf,+sse,+sse2,+sse3,+sse4.1,+ssse3,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
attributes #1 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="penryn" "target-features"="+cx16,+cx8,+fxsr,+mmx,+sahf,+sse,+sse2,+sse3,+sse4.1,+ssse3,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
!llvm.module.flags = !{!0, !1}
!llvm.ident = !{!2}
!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 7, !"PIC Level", i32 2}
!2 = !{!"clang version 9.0.0 (tags/RELEASE_900/final)"}
!3 = !{!4}
!4 = !{i64 2, i64 3, i1 false}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant