sshock / AFFLIBv3

AFF is an open and extensible file format to store disk images and associated metadata.
Other
80 stars 21 forks source link

Build error with gcc-14 -Wincompatible-pointer-types #53

Closed kwizart closed 8 months ago

kwizart commented 9 months ago

gcc-14 in fedora rawhide (f40) currently fails to build from source the current afflib.

https://fedoraproject.org/wiki/Changes/GNUToolchainF40 https://fedoraproject.org/wiki/Changes/PortingToModernC#Use_of_incompatible_pointer_types_without_a_cast

One can reproduce with an older gcc with -Werror=incompatible-pointer-types

gcc -fno-strict-overflow -Wsign-compare -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -fexceptions -fexceptions -fexceptions -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -mbranch-protection=standard -fasynchronous-unwind-tables -fstack-clash-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fPIC -I/builddir/build/BUILD/AFFLIBv3-3.7.20/include -I/usr/include/python3.12 -c pyaff.c -o build/temp.linux-aarch64-cpython-312/pyaff.o
pyaff.c: In function ‘__pyx_pf_5pyaff_6affile___cinit__’:
pyaff.c:3082:20: error: assignment to ‘struct AFFILE *’ from incompatible pointer type ‘AFFILE *’ {aka ‘struct _AFFILE *’} [-Wincompatible-pointer-types]
 3082 |   __pyx_v_self->af = af_open(__pyx_t_7, O_RDONLY, 0);
      |                    ^
pyaff.c:3124:53: error: passing argument 1 of ‘af_get_imagesize’ from incompatible pointer type [-Wincompatible-pointer-types]
 3124 |   __pyx_v_self->size = af_get_imagesize(__pyx_v_self->af);
      |                                         ~~~~~~~~~~~~^~~~
      |                                                     |
      |                                                     struct AFFILE *
In file included from pyaff.c:1206:
/builddir/build/BUILD/AFFLIBv3-3.7.20/include/afflib/afflib.h:271:34: note: expected ‘AFFILE *’ {aka ‘struct _AFFILE *’} but argument is of type ‘struct AFFILE *’
  271 | int64_t af_get_imagesize(AFFILE *af);   // byte # of last mapped byte in image, or size of device;
      |                          ~~~~~~~~^~
pyaff.c: In function ‘__pyx_pf_5pyaff_6affile_2read’:
pyaff.c:3321:41: error: passing argument 1 of ‘af_read’ from incompatible pointer type [-Wincompatible-pointer-types]
 3321 |   __pyx_v_written = af_read(__pyx_v_self->af, __pyx_t_5, __pyx_v_size);
      |                             ~~~~~~~~~~~~^~~~
      |                                         |
      |                                         struct AFFILE *
/builddir/build/BUILD/AFFLIBv3-3.7.20/include/afflib/afflib.h:229:27: note: expected ‘AFFILE *’ {aka ‘struct _AFFILE *’} but argument is of type ‘struct AFFILE *’
  229 | ssize_t   af_read(AFFILE *af,unsigned char *buf,ssize_t count);
      |                   ~~~~~~~~^~
pyaff.c: In function ‘__pyx_pf_5pyaff_6affile_4seek’:
pyaff.c:3564:36: error: passing argument 1 of ‘af_seek’ from incompatible pointer type [-Wincompatible-pointer-types]
 3564 |   __pyx_t_1 = (af_seek(__pyx_v_self->af, __pyx_v_offset, __pyx_v_whence) < 0);
      |                        ~~~~~~~~~~~~^~~~
      |                                    |
      |                                    struct AFFILE *
/builddir/build/BUILD/AFFLIBv3-3.7.20/include/afflib/afflib.h:231:27: note: expected ‘AFFILE *’ {aka ‘struct _AFFILE *’} but argument is of type ‘struct AFFILE *’
  231 | uint64_t  af_seek(AFFILE *af,int64_t pos,int whence); // returns new position
      |                   ~~~~~~~~^~
pyaff.c: In function ‘__pyx_pf_5pyaff_6affile_6get_seg’:
pyaff.c:3788:39: error: passing argument 1 of ‘af_get_seg’ from incompatible pointer type [-Wincompatible-pointer-types]
 3788 |   __pyx_t_6 = (af_get_seg(__pyx_v_self->af, __pyx_t_5, NULL, NULL, (&__pyx_v_buflen)) != 0);
      |                           ~~~~~~~~~~~~^~~~
      |                                       |
      |                                       struct AFFILE *
/builddir/build/BUILD/AFFLIBv3-3.7.20/include/afflib/afflib.h:296:28: note: expected ‘AFFILE *’ {aka ‘struct _AFFILE *’} but argument is of type ‘struct AFFILE *’
  296 | int     af_get_seg(AFFILE *af,const char *name,uint32_t *arg,
      |                    ~~~~~~~~^~
pyaff.c:3851:39: error: passing argument 1 of ‘af_get_seg’ from incompatible pointer type [-Wincompatible-pointer-types]
 3851 |   __pyx_t_6 = (af_get_seg(__pyx_v_self->af, __pyx_t_5, NULL, __pyx_t_7, (&__pyx_v_buflen)) != 0);
      |                           ~~~~~~~~~~~~^~~~
      |                                       |
      |                                       struct AFFILE *
/builddir/build/BUILD/AFFLIBv3-3.7.20/include/afflib/afflib.h:296:28: note: expected ‘AFFILE *’ {aka ‘struct _AFFILE *’} but argument is of type ‘struct AFFILE *’
  296 | int     af_get_seg(AFFILE *af,const char *name,uint32_t *arg,
      |                    ~~~~~~~~^~
pyaff.c: In function ‘__pyx_pf_5pyaff_6affile_8get_seg_names’:
pyaff.c:4013:36: error: passing argument 1 of ‘af_rewind_seg’ from incompatible pointer type [-Wincompatible-pointer-types]
 4013 |   (void)(af_rewind_seg(__pyx_v_self->af));
      |                        ~~~~~~~~~~~~^~~~
      |                                    |
      |                                    struct AFFILE *
/builddir/build/BUILD/AFFLIBv3-3.7.20/include/afflib/afflib.h:301:31: note: expected ‘AFFILE *’ {aka ‘struct _AFFILE *’} but argument is of type ‘struct AFFILE *’
  301 | int     af_rewind_seg(AFFILE *af); // rewind seg pointer to beginning
      |                       ~~~~~~~~^~
pyaff.c:4025:46: error: passing argument 1 of ‘af_get_next_seg’ from incompatible pointer type [-Wincompatible-pointer-types]
 4025 |     __pyx_t_5 = (af_get_next_seg(__pyx_v_self->af, __pyx_t_3, __pyx_t_4, NULL, NULL, NULL) == 0);
      |                                  ~~~~~~~~~~~~^~~~
      |                                              |
      |                                              struct AFFILE *
/builddir/build/BUILD/AFFLIBv3-3.7.20/include/afflib/afflib.h:298:33: note: expected ‘AFFILE *’ {aka ‘struct _AFFILE *’} but argument is of type ‘struct AFFILE *’
  298 | int     af_get_next_seg(AFFILE *af,char *segname,size_t segname_len,
      |                         ~~~~~~~~^~
pyaff.c: In function ‘__pyx_pf_5pyaff_6affile_10tell’:
pyaff.c:4180:61: error: passing argument 1 of ‘af_tell’ from incompatible pointer type [-Wincompatible-pointer-types]
 4180 |   __pyx_t_1 = __Pyx_PyInt_From_uint64_t(af_tell(__pyx_v_self->af)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 66, __pyx_L1_error)
      |                                                 ~~~~~~~~~~~~^~~~
      |                                                             |
      |                                                             struct AFFILE *
/builddir/build/BUILD/AFFLIBv3-3.7.20/include/afflib/afflib.h:232:27: note: expected ‘AFFILE *’ {aka ‘struct _AFFILE *’} but argument is of type ‘struct AFFILE *’
  232 | uint64_t  af_tell(AFFILE *af);
      |                   ~~~~~~~~^~
pyaff.c: In function ‘__pyx_pf_5pyaff_6affile_12close’:
pyaff.c:4265:31: error: passing argument 1 of ‘af_close’ from incompatible pointer type [-Wincompatible-pointer-types]
 4265 |   (void)(af_close(__pyx_v_self->af));
      |                   ~~~~~~~~~~~~^~~~
      |                               |
      |                               struct AFFILE *
/builddir/build/BUILD/AFFLIBv3-3.7.20/include/afflib/afflib.h:195:26: note: expected ‘AFFILE *’ {aka ‘struct _AFFILE *’} but argument is of type ‘struct AFFILE *’
  195 | int     af_close(AFFILE *af);
      |                  ~~~~~~~~^~
error: command '/usr/bin/gcc' failed with exit code 1
sshock commented 9 months ago

I'm not able to test this at the moment; can you tell me if it fixes the build to change line 835 of pyaff.c from this:

struct AFFILE *af;

to this?

AFFILE *af;
kwizart commented 9 months ago

Thanks for looking into this.

Removing the struct then leads to lot of occurrence of

/builddir/build/BUILD/AFFLIBv3-3.7.20/include/afflib/afflib.h:271:34: note: expected ‘AFFILE *’ {aka ‘struct _AFFILE *’} but argument is of type ‘struct AFFILE *’

But removing the struct on that line then leads to missing function definitions...

sshock commented 9 months ago

I wonder if regenerating pyaff.c with a newer version of cython would fix the problem. I installed cython but it isn't working for me right now. Is that something you could try?

p-linnane commented 9 months ago

I wonder if regenerating pyaff.c with a newer version of cython would fix the problem. I installed cython but it isn't working for me right now. Is that something you could try?

This is something we are doing in Homebrew to fix building with Python 3.12: https://github.com/Homebrew/homebrew-core/blob/master/Formula/a/afflib.rb#L40

sshock commented 8 months ago

@p-linnane I just committed a new pyaff.c generated with the latest Cython, 3.0.8, so you might not have to regenerate it anymore.

sshock commented 8 months ago

Removing the struct then leads to lot of occurrence of

Interesting. I finally got a chance to test this and for me changing struct AFFILE *af; to AFFILE *af; absolutely fixed all these incompatible pointer type warnings/errors.

sshock commented 8 months ago

@kwizart , I committed the fix for this; please try again and share the output if you are still seeing errors

kwizart commented 8 months ago

OK, I confirm this is fixed with the current code base.

Thanks!