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

STD lib identification wrong #237

Closed
Konstantin8105 opened this issue Oct 15, 2017 · 3 comments
Closed

STD lib identification wrong #237

Konstantin8105 opened this issue Oct 15, 2017 · 3 comments
Labels

Comments

@Konstantin8105
Copy link
Contributor

If we transpile next C code:

#include <stdio.h>

double acos(double var){
        printf("We inside acos()");
        return 0.0;
}

int main(){
        printf("Hello world");
        acos(1.0);
        return 0;
}

We see function acos look like from standart library - <math.h> and with indentical signature.
Result:

package main

import "io/ioutil"
import "testing"
import "math"
import "os"
import "github.com/elliotchance/c2go/noarch"

// .......

func main() {
        __init()
        noarch.Printf([]byte("Hello world\x00"))
        math.Acos(1)
        return
}

function acos are lost.

@elliotchance
Copy link
Owner

Ah, thanks for catching that. It's an interesting one because that code should not work in C (it would in C++).

As part of the function replacement process it should check if the function is already defined before replacing the definition.

@Konstantin8105
Copy link
Contributor Author

Konstantin8105 commented Oct 16, 2017

Also, we can create link between "library - functions" and if we use library so we cannot add import and replace function, but like I understood - it is long way.

For example /test/exit.c is depended of test.h.
Let's find that:

$ clang  -MM -c exit.c
exit.o: exit.c tests.h

or full list

$ clang -M -c exit.c
exit.o: exit.c /usr/include/stdlib.h /usr/include/features.h \
  /usr/include/stdc-predef.h /usr/include/x86_64-linux-gnu/sys/cdefs.h \
  /usr/include/x86_64-linux-gnu/bits/wordsize.h \
  /usr/include/x86_64-linux-gnu/gnu/stubs.h \
  /usr/include/x86_64-linux-gnu/gnu/stubs-64.h \
  /usr/lib/llvm-3.8/bin/../lib/clang/3.8.0/include/stddef.h \
  /usr/include/x86_64-linux-gnu/bits/waitflags.h \
  /usr/include/x86_64-linux-gnu/bits/waitstatus.h /usr/include/endian.h \
  /usr/include/x86_64-linux-gnu/bits/endian.h \
  /usr/include/x86_64-linux-gnu/bits/byteswap.h \
  /usr/include/x86_64-linux-gnu/bits/types.h \
  /usr/include/x86_64-linux-gnu/bits/typesizes.h \
  /usr/include/x86_64-linux-gnu/bits/byteswap-16.h \
  /usr/include/x86_64-linux-gnu/sys/types.h /usr/include/time.h \
  /usr/include/x86_64-linux-gnu/sys/select.h \
  /usr/include/x86_64-linux-gnu/bits/select.h \
  /usr/include/x86_64-linux-gnu/bits/sigset.h \
  /usr/include/x86_64-linux-gnu/bits/time.h \
  /usr/include/x86_64-linux-gnu/sys/sysmacros.h \
  /usr/include/x86_64-linux-gnu/bits/pthreadtypes.h \
  /usr/include/alloca.h \
  /usr/include/x86_64-linux-gnu/bits/stdlib-float.h tests.h \
  /usr/include/string.h /usr/include/xlocale.h /usr/include/math.h \
  /usr/include/x86_64-linux-gnu/bits/math-vector.h \
  /usr/include/x86_64-linux-gnu/bits/libm-simd-decl-stubs.h \
  /usr/include/x86_64-linux-gnu/bits/huge_val.h \
  /usr/include/x86_64-linux-gnu/bits/huge_valf.h \
  /usr/include/x86_64-linux-gnu/bits/huge_vall.h \
  /usr/include/x86_64-linux-gnu/bits/inf.h \
  /usr/include/x86_64-linux-gnu/bits/nan.h \
  /usr/include/x86_64-linux-gnu/bits/mathdef.h \
  /usr/include/x86_64-linux-gnu/bits/mathcalls.h

See more detail in https://gcc.gnu.org/onlinedocs/gcc-7.2.0/gcc/Preprocessor-Options.html#Preprocessor-Options flag -M:

-M
Instead of outputting the result of preprocessing, output a rule suitable for make describing the dependencies of the main source file. The preprocessor outputs one make rule containing the object file name for that source file, a colon, and the names of all the included files, including those coming from -include or -imacros command-line options.

Unless specified explicitly (with -MT or -MQ), the object file name consists of the name of the source file with any suffix replaced with object file suffix and with any leading directory parts removed. If there are many included files then the rule is split into several lines using ‘\’-newline. The rule has no commands.

This option does not suppress the preprocessor’s debug output, such as -dM. To avoid mixing such debug output with the dependency rules you should explicitly specify the dependency output file with -MF, or use an environment variable like DEPENDENCIES_OUTPUT (see Environment Variables). Debug output is still sent to the regular output stream as normal.

Passing -M to the driver implies -E, and suppresses warnings with an implicit -w.

@elliotchance
Copy link
Owner

Thats great information. It may also come in handy when we are processing multiple input files.

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

No branches or pull requests

2 participants