Bug 2338570 - ghc utils/hp2ps: error: too many arguments to function ‘malloc’; expected 0, have 1
Summary: ghc utils/hp2ps: error: too many arguments to function ‘malloc’; expected 0, ...
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Fedora
Classification: Fedora
Component: ghc
Version: 42
Hardware: Unspecified
OS: Linux
unspecified
medium
Target Milestone: ---
Assignee: Jens Petersen
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2025-01-17 04:14 UTC by Jens Petersen
Modified: 2025-04-07 10:31 UTC (History)
23 users (show)

Fixed In Version: ghc-9.6.6-146.fc42
Clone Of:
Environment:
Last Closed: 2025-04-07 10:31:41 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)

Description Jens Petersen 2025-01-17 04:14:47 UTC
In the Mass rebuild I see all ghc and ghcX.Y versions failing on x86_64 or i686
due to errors like this:



Reproducible: Always

Steps to Reproduce:
1. rebuild ghc or ghcX.Y in current rawhide

Actual Results:  
```
checking for sys/socket.h... yes
checking for special C compiler options needed for large files... no
checking for _FILE_OFFSET_BITS value needed for large files... no
checking for wctype.h... Command line: _build/stage0/bin/ghc -Wall -hisuf dyn_hi -osuf dyn_o -hcsuf dyn_hc -fPIC -dynamic -hide-all-packages -no-user-package-db '-package-env -' '-package-db _build/stage1/inplace/package.conf.d' '-this-unit-id hp2ps-0.1-19b3' '-this-package-name hp2ps' -i -i/builddir/build/BUILD/ghc9.12-9.12.1-build/ghc-9.12.1/_build/stage1/utils/hp2ps/build -i/builddir/build/BUILD/ghc9.12-9.12.1-build/ghc-9.12.1/_build/stage1/utils/hp2ps/build/hp2ps/autogen -i/builddir/build/BUILD/ghc9.12-9.12.1-build/ghc-9.12.1/utils/hp2ps -Irts/include -I_build/stage1/utils/hp2ps/build -optP-include -optP_build/stage1/utils/hp2ps/build/hp2ps/autogen/cabal_macros.h -outputdir _build/stage1/utils/hp2ps/build -XHaskell2010 -no-global-package-db -package-db=/builddir/build/BUILD/ghc9.12-9.12.1-build/ghc-9.12.1/_build/stage1/inplace/package.conf.d -ghcversion-file=rts/include/ghcversion.h -ghcversion-file=rts/include/ghcversion.h -optc-Irts/include -optc-I_build/stage1/utils/hp2ps/build -optc-fPIC -optc-DDYNAMIC -Wnoncanonical-monad-instances -optc-Wno-error=inline -c utils/hp2ps/Utilities.c -o _build/stage1/utils/hp2ps/build/c/Utilities.dyn_o -fsplit-sections -O -H64m
===> Command failed with error code: 1
utils/hp2ps/Utilities.c:6:14: error:
     warning: conflicting types for built-in function ‘malloc’; expected ‘void *(long unsigned int)’ [-Wbuiltin-declaration-mismatch]
        6 | extern void* malloc();
          |              ^~~~~~
  |
6 | extern void* malloc();
  |              ^
utils/hp2ps/Utilities.c:5:1: error:
     note: ‘malloc’ is declared in header ‘<stdlib.h>’
        4 | #include "Error.h"
      +++ |+#include <stdlib.h>
        5 | 
  |
5 | 
  | ^
utils/hp2ps/Utilities.c: In function ‘xmalloc’:
utils/hp2ps/Utilities.c:80:17: error:
     error: too many arguments to function ‘malloc’; expected 0, have 1
       80 |     r = (void*) malloc(n);
          |                 ^~~~~~ ~
   |
80 |     r = (void*) malloc(n);
   |                 ^
utils/hp2ps/Utilities.c:6:14: error:
     note: declared here
        6 | extern void* malloc();
          |              ^~~~~~
  |
6 | extern void* malloc();
  |              ^
utils/hp2ps/Utilities.c: In function ‘xrealloc’:
utils/hp2ps/Utilities.c:92:18: error:
     warning: conflicting types for built-in function ‘realloc’; expected ‘void *(void *, long unsigned int)’ [-Wbuiltin-declaration-mismatch]
       92 |     extern void *realloc();
          |                  ^~~~~~~
   |
92 |     extern void *realloc();
   |                  ^
utils/hp2ps/Utilities.c:92:18: error:
     note: ‘realloc’ is declared in header ‘<stdlib.h>’
   |
92 |     extern void *realloc();
   |                  ^
utils/hp2ps/Utilities.c:94:9: error:
     error: too many arguments to function ‘realloc’; expected 0, have 2
       94 |     r = realloc(p, n);
          |         ^~~~~~~ ~
   |
94 |     r = realloc(p, n);
   |         ^
utils/hp2ps/Utilities.c:92:18: error:
     note: declared here
       92 |     extern void *realloc();
          |                  ^~~~~~~
   |
92 |     extern void *realloc();
   |                  ^
`gcc' failed in phase `C Compiler'. (Exit code: 1)
Command failed
Build failed.
error: Bad exit status from /var/tmp/rpm-tmp.BmfaoN (%build)
```

Expected Results:  
No error like before

F42 Mass rebuild links to failed tasks:

    ghc: https://koji.fedoraproject.org/koji/taskinfo?taskID=127955550 (i686)
    ghc8.10: https://koji.fedoraproject.org/koji/taskinfo?taskID=127961525 (i686)
    ghc9.0: https://koji.fedoraproject.org/koji/taskinfo?taskID=127961600 (x86_64)
    ghc9.10: https://koji.fedoraproject.org/koji/taskinfo?taskID=127961582 (i686)
    ghc9.12: https://koji.fedoraproject.org/koji/taskinfo?taskID=127961578 (x86_64)
    ghc9.2: https://koji.fedoraproject.org/koji/taskinfo?taskID=127961607 (x86_64)
    ghc9.4: https://koji.fedoraproject.org/koji/taskinfo?taskID=127961594 (i686)
    ghc9.6: https://koji.fedoraproject.org/koji/taskinfo?taskID=127961656 (i686)
    ghc9.8: https://koji.fedoraproject.org/koji/taskinfo?taskID=127961644 (i686)

(obtained with `koji-tool tasks -L -s fail <pkg>`)

Comment 1 Jens Petersen 2025-01-17 04:27:09 UTC
This can be also be reproduced directly in the ghc-<VERSION>/utils/hp2ps/ source using the Haskell cabal-install build tool (which triggers configure):

$ fedpkg clone ghc9.12  # (or just ghc)
$ cd ghc9.12
$ fedpkg prep
$ cd BUILD/ghc-9.12.1/utils/hp2ps
$ sudo dnf install cabal-install
$ cabal build

(this voids multiple minutes of ghc source building)

Comment 2 Jens Petersen 2025-01-17 04:28:37 UTC
I could imagine there are other related failures in the mass rebuild since this seems unrelated to GHC.

Comment 3 Jens Petersen 2025-01-17 06:07:55 UTC
Perhaps it is some old code dunno?  Though it has worked for 13 years...

https://gitlab.haskell.org/ghc/ghc/-/blob/master/utils/hp2ps/Utilities.c?ref_type=heads

Comment 4 Jens Petersen 2025-01-17 08:49:29 UTC
But there are lots of other type mismatch errors coming up in the mass rebuild unfortunately.

https://kojipkgs.fedoraproject.org/mass-rebuild/f42-failures.html

Comment 5 Jens Petersen 2025-01-17 08:51:20 UTC
From my own packages: I think most of

    chez-scheme
    clang13
    eb
    editline
    emacspeak
    ghc-hashtables
    ghc-language-java
    ghc-readline
    ghc-system-fileio

Comment 6 Jens Petersen 2025-01-17 15:04:22 UTC
decathorp mentioned that "this looks related to the C23 change wrt/ no arguments vs. undefined arguments vs. void argument"
so moving to gcc

Comment 7 Jakub Jelinek 2025-01-17 15:18:17 UTC
Except this is not a gcc bug.  You should fix ghc or wherever it is to be valid C23 or make sure you build with -std=gnu17 if you want to stay in C17.
See https://gcc.gnu.org/gcc-15/porting_to.html for some details.
Note, declarations like
extern void *realloc();
has been obsolescent already in C99, C11 and C17, so programs had at least 14 years to adapt.

Comment 8 Jens Petersen 2025-01-17 16:52:46 UTC
Okay I see: 14 years of ignoring such warnings is certainly a long time... hm

Do you know how many fedora packages are affected roughly?

Perhaps a C23 Fedora Change would have made sense?

Comment 9 Jakub Jelinek 2025-01-17 17:02:42 UTC
David Malcolm should have such data.
In any case, the functions declared with unspecified parameters are a security risk and maintenance burden, all calls to such functions have to get the number and type of their arguments right, the compiler can't diagnose errors about their misuses.
Which is why C89 and C++ introduced declaration of types of the arguments.  C++ has been requiring that since the beginning, C89 just recommending but unspecified ones were accepted for compatibility with K&R.
The C23 change makes void foo (); mean the same thing like in C++, i.e. void foo (void);

Comment 10 Jens Petersen 2025-01-17 18:21:16 UTC
I filed https://gitlab.haskell.org/ghc/ghc/-/issues/25662 upstream, but that is just one of many packages.

Comment 11 Jens Petersen 2025-01-17 18:27:36 UTC
(In reply to Jakub Jelinek from comment #7)
> Except this is not a gcc bug.  You should fix ghc or wherever it is to be
> valid C23 or make sure you build with -std=gnu17 if you want to stay in C17.
> See https://gcc.gnu.org/gcc-15/porting_to.html for some details.
> Note, declarations like
> extern void *realloc();
> has been obsolescent already in C99, C11 and C17, so programs had at least
> 14 years to adapt.

Might be nice to mention this and how to inject -std=gnu17, etc in the Toolchain Change page?
I guess one can append it to CFLAGS?

Comment 12 Jens Petersen 2025-01-23 09:09:09 UTC
Fixed in upstream git by https://gitlab.haskell.org/ghc/ghc/-/merge_requests/13838

Comment 13 Florian Weimer 2025-01-23 09:18:57 UTC
This is not portable:

extern void* malloc(long unsigned int);

Declaring your prototypes for functions that need to reference _t types like size_t is not supported by POSIX. You need to include <stdlib.h>.

Comment 14 Jakub Jelinek 2025-01-23 09:26:00 UTC
And not just generally non-portable, but non-portable for some Fedora architectures as well, e.g. i686 has size_t unsigned int rather than unsigned long int, .

Comment 15 Jens Petersen 2025-01-24 15:06:14 UTC
Thank you for pointing out my elementary mistake :thanks:

I put up https://gitlab.haskell.org/ghc/ghc/-/merge_requests/13853 to use size_t

(Fortunately or not the previous fix is not built in Fedora yet anyway - since I only tried it for ghc9.0
which failed to link its rts on s390x)

Comment 16 Jakub Jelinek 2025-01-27 09:52:00 UTC
Why don't you just #include <stdlib.h> and drop the declaration altogether?
Even C89 had malloc/realloc/free/calloc etc. declared in stdlib.h, I think even K&R had that.

Comment 17 Jens Petersen 2025-01-27 11:10:32 UTC
Okay I see, thanks, now I understand that is even what Florian suggested above...

Comment 18 Jens Petersen 2025-01-27 14:26:08 UTC
Does the order of the #include matter particularly?

```
@@ -2,8 +2,7 @@
 #include <stdio.h>
 #include <string.h>
 #include "Error.h"
-
-extern void* malloc();
+#include <stdlib.h>
```
?

Comment 19 Jakub Jelinek 2025-01-27 14:38:44 UTC
The order of standard includes doesn't matter, for others it really matters what they are doing.
Though, as a matter of style, usually system headers are included first, followed by project local headers, at least most of the time (with some exceptions like autoconf generated config.h or similar).

Comment 20 Jens Petersen 2025-01-28 09:51:30 UTC
Thanks

https://gitlab.haskell.org/ghc/ghc/-/merge_requests/13863

Hopefully the last one.

Comment 21 Aoife Moloney 2025-02-26 13:24:31 UTC
This bug appears to have been reported against 'rawhide' during the Fedora Linux 42 development cycle.
Changing version to 42.


Note You need to log in before you can comment on or make changes to this bug.