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

Can obliv-c complie c++ #89

Open
siaaron045 opened this issue Apr 19, 2019 · 9 comments
Open

Can obliv-c complie c++ #89

siaaron045 opened this issue Apr 19, 2019 · 9 comments

Comments

@siaaron045
Copy link

I am sorry to trouble you.
I have a question but do not know who can help me.
I want to compile c++ project in obliv-c . Can obliv-c complie c++?
the error is

/usr/include/string.h[43:0-19] : syntax error
Parsing errorFatal error: exception Frontc.ParseError("Parse error")

Thank you very much!

@weikengchen
Copy link
Contributor

Nope. Obliv-C relies on CIL, which can basically support many features in C, but no guarantee in C++. https://people.eecs.berkeley.edu/~necula/cil/

@siaaron045
Copy link
Author

Thank you for your reply.
And do you know which garble project can compile c++ programs?
Thanks a million.

@samee
Copy link
Owner

samee commented Apr 21, 2019

Thanks for your interest in this. The first step is figuring out how to mix C and C++ in general, without Obliv-C being in the mix. Here is a good place to get started: https://isocpp.org/wiki/faq/mixing-c-and-cpp, but you can probably find others online.

After that, you should be able to link Obliv-C functions and C++ together. You'll still have to keep the obliv parts away from C++, but things should otherwise work. Let us know if you bump into problems.

@siaaron045
Copy link
Author

I am trying to make it .But I do not know how oblivcc (in"oblivc/bin")works. It is a executable file.
A: When i trying to create a *.o file use the command(oblivcc)and then create a static lib *.a file,it tell me that the *.o file which i create in the last step is unrecognized file format. What oblivcc is ? Is it a compiler like gcc and g++?
B: On the other hand,when i use g++ to create a *.o file directly,the warning is header file was not find.
I do not find them too, where are u put them?:) It may be that u were create a liboblivc.a file use all the *.c file.Could you tell how to create a *.a file use my own project together with your liboblivc.a .
I have already created a c++ lib use my c++ project which has a independent compiler too but use oblivcc or g++ can not link it with oblivc file .So i plan to lib the oblivc file too.
The main problem is whatever i use g++ or oblivcc can not create static lib.
Thanks a million.

@samee
Copy link
Owner

samee commented Apr 25, 2019

oblivcc is just a Bash shell script. You can open it up in your editor or just look here to learn what it does: https://github.com/samee/obliv-c/blob/obliv-c/bin/oblivcc

Can you list the exact commands you are trying? And the path where your files are? It's hard to figure out what's wrong from the description.

@siaaron045
Copy link
Author

I have created three files "gazelle.c" “gazelle.h” and “gazelle.oc”in oblivc/test/oblivc/garble.They can run accurately.
Then i want to pack them to a static lib (already transformed the main() into garble() ).
Commands:
../../../bin/oblivcc -c gazelle.c gazelle.oc #create a gazelle.o
ar cr libgable.a gazelle.o #create a static lib libgable.a
../../../bin/oblivcc main.c -L. -lobliv -lgable #link the main.c together with libobliv.a and libgable.a
the error is :
/tmp/cil-Rj29F_ej.o:in function ‘main’:
cil-InHj3WZ2.cil.c:(.text+0xa):‘garble’ undefined reference
I am trying to change the gcc in oblivcc to g++,but the error still exists.
I have already defined the function garble() in main.c and main.h.
what libobliv.a is? Is it a static lib include all the files you created?
Thank you!

@samee
Copy link
Owner

samee commented Apr 26, 2019

Yes, libobliv.a gets created in _build/ once you run make in the Obliv-C source folder. Try to simplify the second oblivcc to just directly calling gcc with -L../../../_build. If that doesn't work attach the source files here and we can take a look.

Btw, you shouldn't need to create a .a archive. It should be possible to directly link in a .o object file. My wild guess is that C++ name mangling was biting you, but your example doesn't use C++, so I am a bit confused right now.

@siaaron045
Copy link
Author

I have tried it again and again,but failed.
garble.zip
I would appreciate it if you could spare some time to help me.

@samee
Copy link
Owner

samee commented Apr 27, 2019

Ok, I made a few changes to make this work:

$ diff -ru garble garble-modified/
diff -ru garble/gazelle.c garble-modified/gazelle.c
--- garble/gazelle.c	2019-04-27 13:23:22.000000000 -0700
+++ garble-modified/gazelle.c	2019-04-27 11:36:51.730552256 -0700
@@ -4,7 +4,7 @@
 #include<pthread.h>
 //#include<gazelle.oc>
 #include"gazelle.h"
-void sereveprog(void *args)
+void* sereveprog(void *args)
 {
   ProtocolDesc pd;
   Args *ref=args;
@@ -15,8 +15,9 @@
   setCurrentParty(&pd,1);
   execYaoProtocol(&pd,gazelle,&(*ref).io);
   cleanupProtocol(&pd);
+  return NULL;
 }
-void clientprog(void *args)
+void* clientprog(void *args)
 {
   ProtocolDesc pd;
   Args *ref=args;
@@ -27,9 +28,10 @@
   setCurrentParty(&pd,2);
   execYaoProtocol(&pd,gazelle,&(*ref).io);
   cleanupProtocol(&pd);
+  return NULL;
 }
-extern "C"
-{
 int garble()
 {
  // helib();
@@ -121,4 +123,4 @@
   printf("\n");
   return 0;
 }
-}
Only in garble-modified/: gazelle.c.o
diff -ru garble/gazelle.h garble-modified/gazelle.h
--- garble/gazelle.h	2019-04-25 15:15:44.000000000 -0700
+++ garble-modified/gazelle.h	2019-04-27 11:37:09.127684745 -0700
@@ -29,5 +29,5 @@
   char* port;
 }Args;
 void gazelle(void* args);
-void sereveprog(void *args);
-void clientprog(void *args);
+void* sereveprog(void *args);
+void* clientprog(void *args);
Only in garble-modified/: gazelle.oc.o
diff -ru garble/main.c garble-modified/main.c
--- garble/main.c	2019-04-27 13:28:50.000000000 -0700
+++ garble-modified/main.c	2019-04-27 11:39:09.472600331 -0700
@@ -1,19 +1,9 @@
-#include "main.h"
 #include <stdio.h>
 
-//include "hr-dmethod1.h"
-
-#ifdef __cplusplus
-extern "C"{
-#endif
 int garble();
-#ifdef _cplusplus
-}
-#endif
-//int helib();
+
 int main()
 {
-  // helib();
   garble();
   return 0;
 }

And then compilation (I didn't try running it, just compiled):

$ alias oblivcc=$HOME/Projects/obliv-c/bin/oblivcc
$ oblivcc -c gazelle.oc -o gazelle.oc.o
$ gcc -c main.c -o main.c.o
$ gcc -c gazelle.c -o gazelle.c.o -I $HOME/Projects/obliv-c/src/ext/oblivc
$ oblivcc gazelle.c.o gazelle.oc.o main.c.o -pthread

This creates an a.out. Hope this helps.

Now, a few points about C and C++ linking (these are independent of Obliv-C):

  • It's __cplusplus with two underscores, not one.
  • At least without the HElib headers, you are not using any C++ code in any of the files. That means you don't need g++, only gcc and oblivcc. That also means you don't actually need extern "C" either. Anywhere. You can completely remove them all, and it will still work.
  • The only time you should need extern "C" is in a header file that is exporting functions accessible both from C and C++. All it does is that it prevents C++ name mangling (you can google that).
  • You definitely don't need main.h. That file shouldn't exist.
  • Instead of declaring garble() in main.c, you can include garble.h from main.c

The other thing I noticed is that your client and server are in the same process, different threads. I don't know why you are doing that, but garbled circuits is meant for 2PC, which usually means two parties in two different machines. Let me know if you run into other issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants