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

Inline Assembler #228

Open
mrigger opened this issue Sep 8, 2017 · 7 comments
Open

Inline Assembler #228

mrigger opened this issue Sep 8, 2017 · 7 comments

Comments

@mrigger
Copy link

mrigger commented Sep 8, 2017

Inline assembler is not supported by c2go, for example, the code fragment below.

unsigned long rdtsc() {
  unsigned int tickl, tickh;
  asm("rdtsc":"=a"(tickl),"=d"(tickh));
  return ((long)tickh << 32)|tickl;
}

Currently, having inline assembler in a program to be converted results in an error message: panic: unknown node type: 'GCCAsmStmt 0x3a991f8 <line:5:3, col:38>'.

Note that sqlite3 also contains a similar code fragment.

@cznic
Copy link

cznic commented Sep 8, 2017

Note that sqlite3 also contains a similar code fragment.

Link?

@mrigger
Copy link
Author

mrigger commented Sep 8, 2017

You can download sqlite3 from https://www.sqlite.org/snapshot/sqlite-snapshot-201708251543.tar.gz and grep for rdtsc (or use this link to an unofficial repo). It contains this fragment:

#elif (defined(__GNUC__) && defined(__x86_64__))

  __inline__ sqlite_uint64 sqlite3Hwtime(void){
      unsigned long val;
      __asm__ __volatile__ ("rdtsc" : "=A" (val));
      return val;
  }

@elliotchance elliotchance added this to the v0.16.x Radium milestone Sep 8, 2017
@elliotchance
Copy link
Owner

Thanks for reporting this. It's interesting that you ran into this error when the mac and linux versions of clang on Travis did not. It must be because the preprocessor did not output this code.

Unfortunately Go does not support inline asm, so I'm not sure what the longer term fix for this is (perhaps using configuration to stub off such functions that contain asm). However, I will put a fix for the syntax parser in today.

@elliotchance
Copy link
Owner

See #229

@mrigger
Copy link
Author

mrigger commented Sep 11, 2017

Thanks for addressing the issue! I did not actually run into this problem on sqlite3; I'm just looking how different projects handle inline assembly. In Sulong, a C/LLVM IR interpreter on the JVM, we want to support inline assembly and have started to implement inline assembly for AMD64 by emulating its behavior in Java. For example, see the implementation of the rdtsc instructions: click me.

I'm currently doing an analysis of >1000 Github projects to determine which inline assembly instructions to implement to support as many projects as possible. rdtsc is one of the instructions that is widely used and occurs in 25% of the projects that use inline assembly. I can post a link to the study once it is completed, if you are interested.

@elliotchance
Copy link
Owner

That's interesting I would like to see the results of the study.

I'm not at all familiar with assembly. However if it is a requirement people need when converting their C code there are some more creative solutions that may work...

@Konstantin8105
Copy link
Contributor

Konstantin8105 commented Nov 23, 2017

In according to README of project https://github.com/minio/c2goasm , this is can help.
Example of using in article: https://blog.minio.io/c2goasm-c-to-go-assembly-bb723d2f777f
I haven't any expertise about assembler.

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

4 participants