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

Test ffi008 fails with "multiple definition of `mystruct'" #4914

Open
bavier opened this issue Apr 13, 2022 · 0 comments
Open

Test ffi008 fails with "multiple definition of `mystruct'" #4914

bavier opened this issue Apr 13, 2022 · 0 comments

Comments

@bavier
Copy link

bavier commented Apr 13, 2022

Steps to Reproduce

$ guix time-machine --commit=a62f0f6d85ca1c16674e6fcf284c5aca08986603 -- build [email protected]

This uses gcc 10.3.0 and binutils 2.37

Expected Behavior

Test should pass.

Observed Behavior

The following error message:

    ffi008:
Error: test/ffi008
ld: /tmp/guix-build-idris-1.3.3.drv-0/ccmIt9AI.o:(.bss.mystruct+0x0): multiple definition of `mystruct'; /tmp/guix-build-idris-1.3.3.drv-0/cc3UDCaU.o:(.bss.mystruct+0x0): first defined here
collect2: error: ld returned 1 exit status
run.sh: line 3: ./ffi008: No such file or directory

FAIL (8.87s)
      --- test/ffi008/output    2022-04-13 04:43:20.294548527 +0000
      +++ test/ffi008/expected.out      1970-01-01 00:00:01.000000000 +0000
      @@ -1 +1,5 @@
      -FAILURE: "gcc" ["-fwrapv","-fno-strict-overflow","-std=c99","-pipe","-fdata-sections","-ffunction-sections","-D_POSIX_C_SOURCE=200809L","-DHAS_PTHREAD","-DIDRIS_ENABLE_STATS","-I.","-Wl,-gc-sections","/tmp/guix-build-idris-1.3.3.drv-0/idris2352-0.c","-L/gnu/store/a6181fb8957g7ayrgmqxgys4lcy7gxqf-idris-1.3.3/lib/idris/rts","-lidris_rts","-lgmp","-DIDRIS_GMP","-lpthread","-I/gnu/store/a6181fb8957g7ayrgmqxgys4lcy7gxqf-idris-1.3.3/lib/idris/rts","-lm","-I.","-I/gnu/store/a6181fb8957g7ayrgmqxgys4lcy7gxqf-idris-1.3.3/lib/idris/libs/contrib","-I../base","-I../prelude","-I.","-I/gnu/store/a6181fb8957g7ayrgmqxgys4lcy7gxqf-idris-1.3.3/lib/idris/libs/prelude","-I/gnu/store/a6181fb8957g7ayrgmqxgys4lcy7gxqf-idris-1.3.3/lib/idris/libs/base","ffi008.c","-o","ffi008"]
      +True
      +True
      +a: 122 b: 0
      +4
      +00000010
      \ No newline at end of file

      Use -p '/ffi008/' to rerun this test only.

Suggested fix

Currently the mystruct structure becomes defined in both the linked ffi008.o and the generated idris code, via the %include C "ffi008.h". The structure should be defined in the .c and only declared in .h. The following patch fixes the test for me:

--- a/test/ffi008/ffi008.h      1969-12-31 18:00:01.000000000 -0600                                                                                                                                                                                                             
+++ a/test/ffi008/ffi008.h      2022-04-13 00:32:35.561262598 -0500                                                                                                                                                                                                             
@@ -10,7 +10,7 @@                                                                                                                                                                                                                                                               
     int16_t b;                                                                                                                                                                                                                                                                 
 };                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                
-struct test2 mystruct;                                                                                                                                                                                                                                                         
+extern struct test2 mystruct;                                                                                                                                                                                                                                                  
                                                                                                                                                                                                                                                                                
 int size1(void);                                                                                                                                                                                                                                                               
 int size2(void);                                                                                                                                                                                                                                                               
--- a/test/ffi008/ffi008.c      1969-12-31 18:00:01.000000000 -0600                                                                                                                                                                                                             
+++ a/test/ffi008/ffi008.c      2022-04-13 00:32:53.145186302 -0500                                                                                                                                                                                                             
@@ -11,6 +11,8 @@                                                                                                                                                                                                                                                               
     return sizeof(struct test2);                                                                                                                                                                                                                                               
 }                                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                                
+struct test2 mystruct;                                                                                                                                                                                                                                                         
+                                                                                                                                                                                                                                                                               
 void print_mystruct(void) {                                                                                                                                                                                                                                                    
     printf("a: %d b: %d\n", mystruct.a, mystruct.b);                                                                                                                                                                                                                           
 }                                                                                                                                                                                                                                                                              
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

1 participant