1# $NetBSD: HACKS,v 1.253 2025/05/06 13:03:23 rin Exp $
2#
3# This file is intended to document workarounds for currently unsolved
4# (mostly) compiler bugs.
5#
6# Format:
7#   hack            title
8#   cdate           creation date
9#   mdate           mod date
10#   who                       responsible developer
11#   port            ...
12#           affected ports, space separated, if not "all"
13#   file            affected file : revision : line from : line to
14#           affected files and revision and line numbers describing hack
15#           multiple lines if necessary.
16#   pr                        NNNN ...
17#           problem reports this hack works around, if known. Space
18#           separated.
19#   regress                   src/regress/directory/where/test/found
20#           regression test directories, if available.
21#   descr
22#           insert short informal description (multi-line). (Longer ones
23#           should be in the PR database. More formal descriptions might
24#           be in the regress tree. See above).
25#   kcah
26#           closing bracket.
27#
28# this is a comment.
29
30hack      llvm needs no-unused-command-line-argument
31mdate     10 May 2020
32who       maxv
33file      share/mk/bsd.lib.mk 1.380 -> 1.381
34descr
35          To avoid LLVM warnings when compiling the kernel with special
36          CFLAGS such as KASAN on amd64 or ARMV83_PAC on aarch64, pass
37          -Wno-unused-command-line-argument.
38kcah
39
40hack      static linking with libpthread
41mdate     7 May 2019
42who       maya
43file      src/lib/libpthread/Makefile 1.92 -> 1.94
44descr
45          To avoid some libc thread stub functions being picked up
46          in static builds, link pthread as one section.
47kcah
48
49hack      disable optimization for gcc-9.3 in src/lib/libc/gdtoa/strtod.c
50mdate     18 Sep 2020
51who       christos
52file    src/lib/libc/gdtoa/strtod.c 1.15 -> 1.16
53descr
54          See PR/55668, the program there causes infinite loop
55kcah
56
57hack      gcc-5.3 optimizes memset+malloc -> calloc inside calloc
58mdate     4 May 2016
59who       christos
60file      external/gpl2/lib/libmalloc/lib/Makefile 1.3 -> 1.5
61descr
62          resulting in infinite recursion; we prevent this with
63          -fno-builtin-malloc
64kcah
65
66hack      turn off tree-vrp for parts of ufs_lookup.c
67mdate     28 April 2016
68who       mrg christos
69file      src/sys/ufs/ufs/ufs_lookup.c : 1.144
70pr        51094
71descr
72          with -ftree-vrp enabled in ufs_lookup.c sometimes bad dir
73          panicks are see.
74hcah
75
76hack      netstat ieee1394 address printing.
77mdate     14 Nov 2000
78who       matt
79file      lib/libc/net/getnameinfo.c    : 1.32 : 497 : 503
80descr
81          Because the current implementation of IP over IEEE1394, the
82          fw device address contains more than just the IEEE1394 EUI-64.
83          So when printing out IEEE1394 addresses, ignore the extra stuff.
84kcah
85
86hack      xterm vs. libterm
87mdate     01 Aug 2000
88who       jdc
89file      xsrc/xc/programs/xterm/main.c : 1.2 : 3609 : 3614
90pr        10383
91descr
92          In order to extend the termcap string over 1023 bytes, a ZZ entry was
93          introduced to point to a memory location containing the full entry.
94          Without this hack, xterm will export a termcap containing the ZZ
95          entry, which will then be ignored by libterm.  As xterm modifies the
96          exported termcap, this would cause those modifications to be ignored.
97kcah
98
99hack      wi-at-big-endian-bus
100cdate     15 Mar 2002
101who       martin
102file      dev/ic/wireg.h : 1.20
103descr     Add an option to access the underlying bus in big endian byte order
104          to work around deficiencies in bus_space_{read,write}_* macros.
105          Those don't allow the implementation of a proper pcmcia bus space
106          tag.
107kcah
108
109hack      specific knowledge of colours in curses code
110cdate     Sun Apr  6 11:05:24 BST 2003
111who       jdc
112file      lib/libcurses/color.c : r1.24
113descr
114          Swap red/blue and yellow/cyan colours for COLOR_OTHER.
115          Fix is to enhance libtermcap to understand terminfo-style % sequences.
116          See also:
117              http://mail-index.NetBSD.org/tech-userlevel/2003/04/06/0000.html
118kcah
119
120hack      Compensation for differing types of LINUX_USRSTACK and USRSTACK
121cdate     21 Aug 2003
122who       he
123file      sys/miscfs/procfs/procfs_linux.c : 1.14
124descr
125          Not all ports have LINUX_USRSTACK and/or USRSTACK defined as
126          literals/constants, but refer to variables of a type which is
127          not "unsigned long", causing compilation of procfs_linux.c to
128          fail with "makes integer from pointer without a cast".  This
129          is observed on e.g. the sun3 port.  Ideally the "types" for
130          symbols should be consistent across all ports.
131kcah
132
133hack      gcc4 wrong uninitialized variable
134mdate     10 May 2006
135who       mrg
136file      bin/ksh/eval.c                          : 1.6
137file      bin/sh/histedit.c             : 1.39
138file      bin/sh/parser.c                         : 1.60
139file      crypto/dist/heimdal/kdc/524.c : 1.10
140file      crypto/dist/ssh/sftp.c                  : 1.20
141file      crypto/dist/ssh/ssh-keysign.c : 1.11
142file      dist/ipf/lib/hostname.c                 : 1.2
143file      dist/ipf/tools/ipmon.c                  : 1.8
144file      dist/ntp/ntpd/ntp_request.c   : 1.4
145file      dist/ntp/ntpd/refclock_shm.c  : 1.4
146file      dist/ntp/sntp/timing.c                  : 1.3
147file      dist/pppd/pppstats/pppstats.c : 1.3
148file      dist/tcpdump/print-zephyr.c   : 1.5
149file      distrib/utils/sysinst/aout2elf.c : 1.12
150file      gnu/libexec/uucp/uucico/uucico.c : 1.6
151file      lib/libc/citrus/citrus_csmapper.c : 1.6
152file      lib/libc/citrus/citrus_pivot_factory.c : 1.5
153file      lib/libc/inet/inet_cidr_ntop.c          : 1.3
154file      lib/libc/inet/inet_ntop.c     : 1.3
155file      lib/libc/stdio/vfwprintf.c    : 1.8
156file      libexec/ld.elf_so/arch/m68k/mdreloc.c : 1.20
157file      libexec/ld.elf_so/arch/powerpc/ppc_reloc.c : 1.40
158file      libexec/ld.elf_so/arch/sh3/mdreloc.c : 1.22
159file      libexec/ld.elf_so/arch/sparc/mdreloc.c : 1.39
160file      libexec/ld.elf_so/arch/sparc64/mdreloc.c : 1.39
161file      libexec/ld.elf_so/arch/vax/mdreloc.c    : 1.21
162file      libexec/ld.elf_so/arch/x86_64/mdreloc.c : 1.27
163file      sbin/fsck_ext2fs/dir.c                  : 1.19
164file      sbin/routed/rtquery/rtquery.c : 1.18
165file      sys/arch/amd64/amd64/pmap.c   : 1.26
166file      sys/arch/i386/pci/piixpcib.c  : 1.4
167file      sys/arch/m68k/m68k/pmap_motorola.c      : 1.4
168file      sys/crypto/cast128/cast128.c  : 1.9
169file      sys/ddb/db_command.c                    : 1.86
170file      sys/dev/cardbus/cardbus_map.c : 1.21
171file      sys/dev/fss.c                           : 1.25
172file      sys/dev/ic/igsfb.c            : 1.39
173file      sys/dev/ic/mb86950.c                    : 1.5
174file      sys/dev/ic/midway.c           : 1.71
175file      sys/dev/kttcp.c                         : 1.18
176file      sys/dev/rasops/rasops_bitops.h          : 1.9
177file      sys/dev/pci/cmpci.c           : 1.31
178file      sys/dev/pci/machfb.c                    : 1.45
179file      sys/dev/usb/ohci.c            : 1.174
180file      sys/dev/usb/uhci.c            : 1.196
181file      sys/dev/rasops/rasops_bitops.h          : 1.9
182file      sys/dist/ipf/netinet/ip_nat.c : 1.10
183file      sys/dist/ipf/netinet/ip_rpcb_pxy.c : 1.8
184file      sys/dist/pf/net/pf.c                    : 1.22
185file      sys/fs/udf/udf_vnops.c                  : 1.4
186file      sys/kern/kern_sig.c           : 1.219
187file      sys/kern/tty.c                          : 1.181
188file      sys/net/bpf.c                           : 1.116
189file      sys/net/zlib.c                          : 1.26
190file      sys/netccitt/if_x25subr.c     : 1.37
191file      sys/netinet/in.c              : 1.107
192file      sys/nfs/nfs_serv.c            : 1.108
193file      sys/nfs/nfs_socket.c                    : 1.129
194file      sys/nfs/nfs_syscalls.c                  : 1.91
195file      sys/ufs/lfs/lfs_vfsops.c      : 1.207 [also (char *)]
196file      usr.bin/ftp/ftp.c             : 1.140
197file      usr.bin/find/function.c                 : 1.54
198file      usr.bin/mail/tty.c            : 1.20
199file      usr.bin/msgc/msg_sys.def      : 1.33-1.34
200file      usr.bin/nl/nl.c                         : 1.7
201file      usr.bin/systat/keyboard.c     : 1.23
202file      usr.bin/usbhidctl/usbhid.c    : 1.29
203file      usr.bin/vi/cl/cl_read.c                 : 1.5
204file      usr.bin/vi/ex/ex_cscope.c     : 1.12
205file      usr.bin/vi/ex/ex_tag.c                  : 1.19
206file      usr.bin/vi/vi/v_txt.c                   : 1.15
207file      usr.sbin/altq/altqstat/qdisc_rio.c : 1.4
208file      usr.sbin/cron/do_command.c    : 1.19
209file      usr.sbin/timed/timed/slave.c  : 1.15
210descr
211          GCC 4.1 gets many uninitialised variable warnings wrong.  We should
212          really audit all the old hacks like this when older compilers are
213          removed from the tree, as many are probably no longer required.
214          The problem is that it does not recognize initialization via function
215          call pointer. I.e.
216                    int p;
217                    foo(&p);
218          does not mark p as initialized.
219kcah
220
221hack      gcc4 pointer sign and strict aliasing problems
222mdate     10 May 2006
223who       mrg
224file      bin/ed/Makefile                         : 1.33
225file      distrib/utils/sysinst/Makefile.inc : 1.44
226file      distrib/utils/x_dhclient/Makefile : 1.15
227file      games/bcd/Makefile            : 1.5
228file      games/dab/Makefile            : 1.5
229file      games/larn/Makefile           : 1.17
230file      games/pom/Makefile            : 1.5
231file      lib/libasn1/Makefile                    : 1.26
232file      lib/libcrypt/Makefile                   : 1.17
233file      lib/libgssapi/Makefile                  : 1.16
234file      lib/libhdb/Makefile           : 1.20
235file      lib/libkadm5clnt/Makefile     : 1.21
236file      lib/libkadm5srv/Makefile      : 1.25
237file      lib/libkrb5/Makefile                    : 1.35
238file      lib/libssh/Makefile           : 1.6
239file      lib/libtelnet/Makefile                  : 1.26
240file      libexec/getty/Makefile                  : 1.14
241file      libexec/kadmind/Makefile      : 1.19
242file      libexec/kpasswdd/Makefile     : 1.14
243file      sbin/atactl/Makefile                    : 1.3
244file      sbin/cgdconfig/Makefile                 : 1.7
245file      sbin/clri/Makefile            : 1.13
246file      sbin/dkctl/Makefile           : 1.4
247file      sbin/dump/Makefile            : 1.33
248file      sbin/fdisk/Makefile           : 1.35
249file      sbin/fsck_ext2fs/Makefile     : 1.11
250file      sbin/fsck_ffs/Makefile                  : 1.29
251file      sbin/fsdb/Makefile            : 1.18
252file      sbin/newfs/Makefile           : 1.30
253file      sbin/newfs_sysvbfs/Makefile   : 1.2
254file      sbin/restore/Makefile                   : 1.23
255file      sbin/veriexecctl/Makefile     : 1.11
256file      sys/lib/libsa/Makefile                  : 1.59
257file      sys/arch/evbarm/adi_brh/brh_machdep.c : 1.24
258file      usr.bin/awk/Makefile                    : 1.9
259file      usr.bin/crontab/Makefile      : 1.24
260file      usr.bin/ctags/Makefile                  : 1.8
261file      usr.bin/gzip/Makefile                   : 1.10
262file      usr.bin/ssh/sftp/Makefile     : 1.10
263file      usr.bin/ssh/ssh/Makefile      : 1.25
264file      usr.bin/vi/build/Makefile     : 1.26
265file      usr.bin/telnet/Makefile                 : 1.40
266file      usr.bin/tn3270/tn3270/Makefile          : 1.36
267file      usr.bin/tr/Makefile           : 1.4
268file      usr.sbin/amd/amd/Makefile     : 1.27
269file      usr.sbin/amd/amq/Makefile     : 1.14
270file      usr.sbin/amd/libamu/Makefile  : 1.20
271file      usr.sbin/amd/pawd/Makefile    : 1.5
272file      usr.sbin/bind/Makefile.inc    : 1.22
273file      usr.sbin/bind/libdns/Makefile : 1.3
274file      usr.sbin/bind/named/Makefile  : 1.17
275file      usr.sbin/bootp/bootptest/Makefile : 1.2
276file      usr.sbin/chrtbl/Makefile      : 1.6
277file      usr.sbin/cron/Makefile                  : 1.12
278file      usr.sbin/dhcp/Makefile.inc    : 1.20
279file      usr.sbin/hprop/Makefile                 : 1.13
280file      usr.sbin/installboot/Makefile : 1.35
281file      usr.sbin/ipf/ipftest/Makefile : 1.32
282file      usr.sbin/isdn/isdnd/Makefile  : 1.6
283file      usr.sbin/isdn/isdnmonitor/Makefile : 1.3
284file      usr.sbin/isdn/isdntel/Makefile          : 1.2
285file      usr.sbin/isdn/isdntrace/Makefile : 126
286file      usr.sbin/mopd/common/Makefile : 1.10
287file      usr.sbin/mopd/mopd/Makefile   : 1.9
288file      usr.sbin/mopd/mopprobe/Makefile         : 1.7
289file      usr.sbin/makefs/Makefile      : 1.17
290file      usr.sbin/mscdlabel/Makefile   : 1.5
291file      usr.sbin/pkg_install/add/Makefile : 1.7
292file      usr.sbin/pkg_install/create/Makefile : 1.5
293file      usr.sbin/pkg_install/lib/Makefile : 1.28
294file      usr.sbin/ntp/ntpd/Makefile    : 1.10/1.11
295file      usr.sbin/ntp/ntptime/Makefile : 1.4/1.5
296file      usr.sbin/pppd/Makefile.inc    : 1.3
297file      usr.sbin/pppd/pppd/Makefile   : 1.38
298file      usr.sbin/rarpd/Makefile                 : 1.10
299file      usr.sbin/rbootd/Makefile      : 1.10
300file      usr.sbin/rpc.pcnfsd/Makefile  : 1.17
301file      usr.sbin/tcpdump/Makefile     : 1.42
302descr
303          GCC 4.1 warns on pointer sign comparison/assignments and lots of
304          code does not conform.  For now we use -Wno-pointer-sign and
305          -fno-strict-aliasing.
306kcah
307
308hack      disable ctf for gcc-4.8 build
309mdate     April 3 2014
310who       christos
311file      external/gpl3/gcc/usr.bin/Makefile.frontend       : 1.4
312file      external/gpl3/gcc/usr.bin/Makefile.backend        : 1.5
313descr
314          nbctfconvert -g -L VERSION -g fold-const.o
315          ERROR: fold-const.c: failed to get mapping for tid 79154 \
316                    ((null)) <13532>
317kcak
318
319hack      emacs aborting on exit (libgcc issue)
320mdate     7 November 2011
321who       christos
322file      external/gpl3/gcc/dist/gcc/unwind-dw2-fde.c : 1.2
323descr
324          GCC 4.5.3 now calls __unregister_frame_info_bases() on unloading/exit
325          to do just that. If the symbol requested is not found, then it aborts.
326          emacs 23.3 triggers this assertion. For now disable aborting, and
327          silently ignore.
328kcah
329
330hack      cross-building hack on Darwin
331mdate     20 July 2008
332who       agc
333file      src/distrib/common/Makefile.mdset       : 1.33
334descr
335          Darwin has problems with getopt() when used in mdsetimage -v,
336          due to the difference between BSD and libiberty() getopt
337          implementations, more fully described in
338          http://mail-index.netbsd.org/current-users/2008/06/27/msg003242.html
339          and the subsequent thread.  For just now, we just have an ugly
340          workaround not to call mdsetimage with the -v argument on Darwin
341kcah
342
343hack      avoid rebuilding asn1 libraries
344mdate     03 August 2008
345who       veego
346file      src/crypto/dist/heimdal/lib/asn1/gen.c  : 1.10
347file      src/lib/libasn1/Makefile      : 1.32
348file      src/lib/libhdb/Makefile       : 1.23
349file      src/lib/libgssapi/Makefile    : 1.20
350file      src/lib/libhx509/Makefile     : 1.3
351pr        9702 39185
352descr
353          asn1_compile does not check if generated header files do not have to
354          be rebuild.
355          Generate .hx files and copy it in the Makefiles if they changed.
356kcah
357
358hack      Disable fortification for /usr/bin/makeinfo
359cdata     24 Mar 2014
360who       tron
361file      src/external/gpl2/texinfo/bin/makeinfo/Makefile   : 1.1
362pr        N/A
363descr
364          If "makeinfo" is compiled with "-D_FORTIFY_SOURCE=2" using GCC 4.8.3
365          it fails to process certain texinfo files, e.g. "cl.texi"
366          included in the Emacs 24.3 distribution.
367kcah
368
369hack      Disable Stack Smash Protection for /usr/X11R7/bin/xauth
370cdata     05 Apr 2014
371who       tron
372file      src/external/mit/xorg/bin/xauth/Makefile          : 1.4
373pr        N/A
374descr
375          If "xauth" is compile with "USE_SSP" set to "yes" it fails
376          mysteriously with an error message like this:
377
378          /usr/X11R7/bin/xauth:  file /foo/bar/.Xauthority does not exist
379          /usr/X11R7/bin/xauth:  unable to link authority file /foo/bar/.Xauthority, use /foo/bar/.Xauthority
380
381          The compiler seems to get confused about the two filename variables
382          used in the link(2) system call.
383kcah
384
385hack      g++ 5.x barfs on volatile in constexpr initializers
386cdata     27 Aug 2015
387who       pooka
388file      src/lib/libpthread/pthread_types.h      : 1.17
389pr        lib/49989
390descr
391          Trying to use e.g. pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER
392          in C++ results in:
393                    error: temporary of non-literal type '__pthread_mutex_st'
394                    in a constant expression
395                    constexpr mutex() _NOEXCEPT : __m_(PTHREAD_MUTEX_INITIALIZER) {}
396                    [...]
397                    include/pthread_types.h:101:8: note: '__pthread_mutex_st' is
398                    not literal because:
399                    struct __pthread_mutex_st {
400                    ^
401                    include/pthread_types.h:103:17: note:   non-static data
402                    member '__pthread_mutex_st::ptm_errorcheck' has volatile type
403                    pthread_spin_t ptm_errorcheck;
404kcah
405
406hack      libm cabs{,f,l} and g++
407cdata     11 Jan 2016
408who       christos
409pr        lib/50646
410file      src/external/gpl3/gcc.old/dist/libstdc++-v3/include/std/complex : 1.2
411file      src/external/gpl3/gcc/dist/libstdc++-v3/include/std/complex : 1.2
412descr
413          Our cabs and cabsf have a different argument format on some architectures
414          and for that we have created in libm/compat_cabs{,f}.c. The standard
415          versions in libc are __c99_cabs{,f,l} and there are __RENAME()'s in
416          <complex.h>. G++ uses __builtin_cabs{,f,l} to implement those and they
417          translate by default to cabs{,f,l} which gets defined to cabs{,f} (the
418          wrong function) and an undefined cabsl. I've changed <complex> to use
419          the __c99_cabs{,f,l} directly. Using the __builtin_cabs{,f,l} in gcc is
420          still broken.
421kcah
422
423hack      xorg warnings
424cdate     30 July 2008, 3 June, 2013
425who       mrg
426file      external/mit/xorg/lib/libSM/Makefile : 1.2
427          external/mit/xorg/lib/libX11/Makefile.libx11 : 1.10
428          external/mit/xorg/lib/libXext/Makefile : 1.2
429          external/mit/xorg/lib/libXfont/Makefile : 1.2
430descr
431          Disable several warnings or use -Wno-error across Xorg sources
432          while we get them working
433kcah
434
435hack      32 bit time leftovers
436cdate     11 January 2009
437who       christos
438file      lib/libc/time/localtime.c : 1.41
439          lib/libc/time/zic.c : 1.23
440descr
441          The timezone compiled files still contain 32 bit time_t
442          quantities. I did not want to version the files because
443          the ``parser'' is too ugly for words. What needs to be
444          done, is to rewrite the parser from scratch also to avoid
445          potential core-dumps from parsing invalid files.
446kcah
447
448hack      32 bit time leftovers
449cdate     11 January 2009
450who       christos
451file      various
452descr
453          Many filesystem on-disk formats have 32 bit times.
454kcah
455
456
457port      vax
458
459          hack      gcc10/vax ICE
460          cdate     Sun Jan 22 15:37:56 EST 2023
461          who       christos
462          file      external/mit/xorg/lib/fontconfig/src/Makefile : 1.28
463          descr
464                    Disable optimization on some files
465          kcah
466
467          hack      declare boolean_t in two IPF user-mode programs
468          cdate     Tue Mar  7 19:19:20 CET 2006
469          who       he
470          file      dist/ipf/ipsend/iptests.c : 1.8
471                    dist/ipf/ipsend/sock.c : 1.7
472          descr
473                    The IPF user-mode programs ipsend and iptest first
474                    include <sys/types.h> without _KERNEL defined, and
475                    later include <sys/file.h> with _KERNEL defined.
476                    This causes a build failure when building for vax,
477                    since <sys/device.h> ends up being included without
478                    bollean_t being defined by <sys/types.h>.
479                    Build failure and further details documented in
480                    PR#32907.
481          kcah
482
483          hack      pcc 0.9.9 large string literals
484          cdat      8 July 2008
485          who       gmcgarry
486          file      sys/conf/param.c : 1.58
487          descr
488                    Workaround for pcc 0.9.9 not handling large string literals
489                    which causes kernels with 'options INCLUDE_CONFIG_FILE' to
490                    fail compilation.
491                    There is a proposal on the pcc mailing list to stuff config
492                    file in ELF section.
493          kcah
494
495          hack      Sprinkle -O0 to avoid ICE for GCC10/12
496          cdate     Mon Sep 30 02:55:44 UTC 2024
497          mdate     Sun Apr 13 08:29:42 UTC 2025
498          mdate     2025/04/13 08:31:12
499          who       kalvisd, rin
500          file      external/mit/xorg/lib/gallium/Makefile : 1.57 -
501          file      external/mit/xorg/lib/gallium.old/Makefile : 1.10 -
502          descr
503                    We have ICE for -O[21] even for GCC10/12.
504                    Affected files varies b/w GCC and gallium versions.
505
506                    Note that compiled binary does not work anyway on vax;
507                    they manipulate floating-point numbers as binary, assuming
508                    IEEE 754 format.
509          kcah
510
511port      arm
512
513          hack      gcc-unsigned-compare
514          cdate     09 Mar 2002
515          mdate     18 Mar 2002
516          who       bjh21
517          file      dist/bind/lib/nameser/ns_parse.c : 1.3
518          file      dist/dhcp/minires/ns_parse.c : 1.3
519          file      dist/dhcp/omapip/result.c : 1.2
520          file      dist/dhcp/server/failover.c : 1.3
521          file      gnu/dist/toolchain/bfd/bfd.c : 1.2
522          file      gnu/dist/toolchain/bfd/format.c : 1.2
523          file      gnu/dist/toolchain/gdb/target.c : 1.2
524          file      sys/kern/vfs_subr.c : 1.172
525          descr     When checking that a potentially-unsigned enum is >= 0, assign
526                    it to an int first.  This is necessary to avoid "comparison is
527                    always true" warnings with -fshort-enums.  Casting to an int
528                    really should be enough, but turns out not to be.
529          kcah
530
531          hack      gcc-4.5 arm CNAME hostname lookup failure on
532                    certain DNS environment (probably -ftree-ter problem)
533          cdate     Sat Dec 24 04:59:00 UTC 2011
534          mdate
535          who       tsutsui
536          file      lib/libc/net/Makefile.inc 1.79
537          descr     Hostname lookup against CNAMEs by some commands fails
538                    on certain DNS environments if lib/libc/net/gethnamaddr.c
539                    (ping(8) etc) and lib/libc/net/getaddrinfo.c (ftp(1) etc)
540                    are compiled with -O2, even though nslookup(1) against
541                    the same CNAME returns proper hostname.
542                    They works properly if compiled with -O2 -fno-tree-ter.
543                    Also -O2 fails but -O2 -fno-tree-ter works on the following
544                    test case in gcc bugzilla:
545                    http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48863#c4
546          kcah
547
548port      sh3
549
550          hack      gcc4-sh3-bz2
551          cdate     Sun May 21 03:34:57 UTC 2006
552          mdate     Fri May 16 13:13:00 UTC 2008
553          who       mrg, tsutsui
554          file      lib/libbz2/Makefile : 1.10
555          descr
556                    The in-tree GCC 4.1-based compiler generated too-far
557                    pc-relative addresses.  Hack is to build with
558                    -fno-loop-optimize.
559          kcah
560
561port      m68000
562
563          hack      gcc4-m68000
564          cdate     Fri Feb  8 10:29:37 PST 2008
565          mdate     Sun May  4 15:37:19 UTC 2008
566          who       mrg, tsutsui
567          file      rescue/Makefile     : 1.21
568          file      sbin/dump_lfs/Makefile        : 1.9
569          file      sbin/fsck_ffs/Makefile        : 1.35
570          file      sbin/fsdb/Makefile  : 1.22
571          file      share/mk/sys.mk     : 1.96
572          file      usr.sbin/ndbootd/Makefile     : 1.5
573          descr
574                    Several internal compiler errors with gcc -O1
575                    around 64bit integer arithmetic.
576                    This hack uses -O1 and adds some -fno-tree-foo options
577                    to avoid the problem.
578                    This might be related with GCC Bugzilla Bug 32424.
579          kcah
580
581port      m68k,sh3,vax
582
583          hack      gcc-4.8.1
584          cdate     Wed Nov  6 20:41:35 EST 2013
585          mdate     2014/05/16 09:36:51
586          who       christos
587          file      src/external/gpl3/gcc/lib/libstdc++-v3/Makefile : 1.11
588          descr
589                    compile the followings with -fimplicit-templates to
590                    produce missing instantiation of std::lower_bound expansion
591                    for unsigned long:
592                    - concept-inst.cc
593                    - hashtable_c++0x.cc
594                    - bitmap_allocator.cc
595          kcah
596
597port      sparc
598
599          hack      avoid NULL pointer derefs in savefpstate IPIs and GCC 4.5.3
600          cdate     Sun Aug 14 19:26:48 PDT 2011
601          who       mrg
602          file      sys/arch/sparc64/sparc/cpu.c : 1.234
603          file      sys/arch/sparc64/sparc/cpuvar.h : 1.90
604          file      sys/arch/sparc64/sparc/genassym.cf : 1.67
605          file      sys/arch/sparc64/sparc/locore.s : 1.265
606          descr
607                    Something is wrong with GCC 4.5.3 and the savefpstate IPI.
608                    Post newlock2 there was a bug where a lock was reduced from
609                    IPL_SCHED to IPL_VM (?) and occasionally savefpstate IPI
610                    would crash due to NULL IPI.  This was fixed by re-using the
611                    right IPL value.  However, GCC 4.5.3 build kernels have the
612                    same problems.  For now, the hack is re-instated.
613          kcah
614
615
616port      mips
617
618          hack      mips-shared-linker-load-address
619          cdate     Fri Oct  7 08:33:10 UTC 2005
620          who       simonb
621          file      src/sys/kern/exec_elf32.c : 1.107
622          descr
623                    With COMPAT_16 or previous enabled (which enables
624                    ELF_INTERP_NON_RELOCATABLE) a recent ld.elf_so will
625                    load and run at address 0.  The check to fix this in
626                    rev 1.107 only checks the first psection of the ELF
627                    executable, which may not be loadable.  A more correct
628                    fix is to check the first loadable psection instead of
629                    just the first psection.
630          kcah
631
632          hack      mips-duplicate-ras-end-label
633          cdate     Sat Sep  2 23:29:42 2006
634          who       martin
635          file      src/regress/sys/kern/ras/ras3/Makefile : 1.3
636          descr
637                    Add -fno-reorder-blocks to CFLAGS to avoid duplicate
638                    labels by duplicated __asm output from RAS_END()
639                    macro.
640          kcah
641
642          hack      mips-mcount-assembler-warning
643          cdate     Tue Jul 29 14:16:52 UTC 2008
644          who       lukem
645          file      src/lib/libc/gmon/Makefile.inc : 1.8
646          descr
647                    Workaround for PR port-mips/39192.
648                    common/lib/libc/gmon/mcount.c generates a (fatal)
649                    assembler warning on MIPS:
650                              Warning: No .cprestore pseudo-op used in PIC code
651                    Add COPTS.count.c+=-Wa,--no-warn to avoid -Wa,--fatal-warnings
652          kcah
653
654          hack      mips-use-binutils-old
655          cdate     Sun May  7 14:28:55 CEST 2023
656          who       martin
657          file      src/share/mk/bsd.own.mk : 1.1311, 1.1308
658          descr
659                    Use binutils.old for 64bit mips with 32bit userland.
660                    Version 2.39 causes random (cross-) build failures
661                    that are hard to reproduce or analyze.
662          kcah
663
664port      i386
665
666          hack      use volatile intermediate variable to enforce rounding
667          cdate     Tue Aug  1 22:15:55 MEST 2006
668          who       drochner
669          file      src/lib/libm/src/lrintf.c : 1.4
670          file      src/lib/libm/src/s_rintf.c : 1.8
671          descr
672                    gcc-4 does subsequent operations on "float" values within
673                    the i387 FPU without rounding the intermediate results
674          kcah
675
676port      x86
677          hack      turn off optimization for biosdisk_ll.c because otherwise
678                    we are pass the wrong arguments to biosdisk_read().
679                    $ cd /usr/src/sys/arch/i386/floppies/bootflopp-com
680                    $ qemu-system-i386 -nographic -fda boot-com1.fs -boot a
681          cdate     Mon Apr 7 21:09:55 2014 UTC
682          who       christos
683          file      src/sys/arch/i386/stand/lib/Makefile : 1.38
684          descr
685                    Turning on DISK_DEBUG shows the problem. We should find
686                    out which option is causing this.
687          hcah
688
689port      powerpc
690
691          hack      avoid using __builtin_return_address(0) because it fails in
692                    Xorg's module loader
693          cdate     Sat Sep 27 03:52:05 UTC 2008
694          who       macallan
695          file      src/libexec/ld.elf_so/rtld.c : 1.121
696          descr
697                    workaround for PR port-macppc/37812
698          kcah
699
700          hack      define TARGET_SECURE_PLT and HAVE_AS_TLS because when
701                    building the native compiler via build.sh those don't defined
702                    properly.
703          cdate     Sat Mar 12 08:00:00 UTC 2011
704          who       matt
705          file      src/gnu/dist/gcc4/gcc/config/rs6000/netbsd.h : 1.7
706          descr
707                    see above
708          kcah
709
710port      powerpc64
711
712          hack      include _errno.c in libposix so that __errno resolves. It
713                    should resolve from libc's errno, but somehow it does not.
714                    Linker bug?
715          cdate     Thu Oct 27 13:19:47 EDT 2011
716          who       christos
717          file      src/lib/libposix/Makefile: 1.15
718          file      src/lib/librt/Makefile: 1.14
719          descr
720                    workaround for:
721                        libposix_pic.a(cerror.pico)(.text+0x14): unresolvable \
722                        R_PPC64_REL24 relocation against symbol `.__errno'
723          kcah
724
725          hack      rename data() function in mdocml to avoid redefined error.
726                    Compiler/Assembler bug?
727          cdate     Sat Oct 29 11:16:01 EDT 2011
728          who       christos
729          file      src/external/bsd/mdocml/tbl_data.c: 1.2
730          descr
731                    workaround for:
732                        {standard input}: Assembler messages:
733                        {standard input}:105: Error: symbol `.data' is already \
734                        defined
735          kcah
736
737port      emips
738
739          hack      Add nop between ctc1 and mtc0 to avoid assembler internal
740                    error
741          cdate     Sat Oct 29 16:57:34 EDT 2011
742          who       christos
743          file      src/sys/arch/mips/mips/mips_fpu.c: 1.7
744          descr
745                    workaround for:
746                        {standard input}: Assembler messages:
747                        {standard input}:730: Internal error!
748                        Assertion failure in append_insn at /usr/src/external/gpl3/\
749                        binutils/dist/gas/config/tc-mips.c line 2910.
750          kcah
751
752port      ia64
753
754          hack      libgcc unwind dummy function
755          cdate     Fri Apr 17 14:31:03 CEST 2015
756          who       martin
757          file      src/external/gpl3/gcc/dist/libgcc/config/ia64/unwind-ia64.c: 1.4
758          descr
759                    Add an empty _Unwind_FindTableEntry() implementation.
760                    In the end we will use our libc stuff, and this should
761                    go away again.
762          kcah
763
764port      x68k
765
766          hack      compiler error with gcc 4.5.x
767          cdate     Fri May 24 13:23:01 EDT 2013
768          who       christos
769          file      src/external/gpl3/gcc/usr.bin/bakend/Makefile: 1.17
770                    xsrc/external/mit/xorg/lib/libGLU/Makefile: 1.11
771          descr
772                    workaround for:
773                    internal compiler error: in cselib_record_set, at cselib.c:1999
774          kcah
775
776hack      fallback to /usr/bin/clang-cpp in rpcgen
777cdate     Wed Jun  5 15:49:27 CEST 2013
778who       joerg
779file      src/usr.bin/rpcgen/rpc_main.c : 1.35
780descr
781          It is undecided which compiler owns /usr/bin/cpp and whether it should
782          exist in a MKGCC=no world. To allow rpcgen to work out-of-the-box,
783          if either gcc or clang is installed, use /usr/bin/clang-cpp as fallback.
784          This applies only if RPCGEN_CPP is not set and /usr/bin/cpp is not executable.
785kcah
786
787port      hppa
788
789          hack      compiler error with gcc 4.5.x
790          cdate     Tue Jul 23 07:42:28 BST 2013
791          who       skrll
792          file      src/sys/lib/libkern/Makefile.libkern: 1.26
793          descr
794                    workaround for unanalysed codegen bug affecting md5c.c.
795          kcah
796
797          hack      gdb vs _rtld_debug_state problem
798          cdate     Thu Mar  5 09:49:53 UTC 2015
799          who       skrll
800          file      src/libexec/ld.elf_so/rtld.c: 1.175
801          descr
802                    workaround for problem where gdb misses the breakpoint on
803                    _rtld_debug_state when the function is only the
804                    bv,n %r0(%rp) instruction - the nullify seems to
805                    confuse something
806          kcah
807
808port      mips64*
809hack      compiler crashes on mips64* with optimization enabled
810cdate     Tue May 13 18:46:48 UTC 2014
811who       macallan
812file      src/external/lgpl3/gmp/lib/libgmp/arch/mips64eb/Makefile.inc: 1.6
813          src/external/lgpl3/gmp/lib/libgmp/arch/mips64eb/config.h: 1.5
814          src/external/lgpl3/gmp/lib/libgmp/arch/mips64el/Makefile.inc: 1.6
815          src/external/lgpl3/gmp/lib/libgmp/arch/mips64el/config.h: 1.5
816descr     workaround for n32 gcc doing unaligned 64bit accesses when optimizing
817pr        48696
818kcah
819
820port      sh3
821hack      compile parse.c in battlestar with -Wno-restrict
822cdate     Mon Oct 28 14:39:35 EDT 2019
823who       christos
824file      /cvsroot/src/games/battlestar/Makefile 1.11
825descr     fails to compile, confused by char words[][];
826          strcpy(words[n - 1], words[n + 1]);
827kcah
828
829port      sh3
830hack      compile ddns.c in dhcpcd with no-stringop-overflow
831cdate     Tue Oct 29 20:25:59 EDT 2019
832who       christos
833file      /cvsroot/src/external/mpl/dhcp/bin/server/Makefile 1.2
834descr     fails to compile, confused by builtin_object_size in strcat(p, ".in..")
835kcah
836
837port      arm
838hack      avoid using labels in a 12-bit constant.
839cdate     Mon Mar 30 05:26:47 2015 UTC
840who       matt
841file      crypto/external/bsd/openssl/lib/libcrypto/arch/arm/aes-armv4.S: 1.2
842descr     workaround for clang misassembling an instruction
843kcah
844
845port      sparc64
846hack      during profiling with -m32 (and ASLR) labels are not generated
847          consistently
848cdate     Sat Feb 11 04:56:37 2017 UTC
849who       christos
850file      /cvsroot/src/crypto/external/bsd/heimdal/lib/libasn1/Makefile: 1.4
851desc      asn1_krb5_asn1.po does not produce the same results during successive
852          compilation runs; it is bimodal. Turning optimization to -O0 fixes
853          the issue
854kcah
855
856port      ia64
857hack      ski emulator crashes
858cdate     Sat Apr 8 18:10:43 2017 UTC
859who       scole
860file      /cvsroot/src/sys/external/bsd/acpica/dist/tables/tbxfload.c: 1.6
861desc
862          ski emulator crashes during acpi detection.  Added a check for
863          uninitialized index.  Submitted a request for change with upstream
864          mailing list, but never got a response
865kcah
866
867port      powerpc
868hack      compile tc.c, logerr.c, ubsan.c with -O0 for clang
869cdate     Wed Jan 29 17:40:19 EST 2020
870who       christos
871file      src/external/bsd/atf/lib/libatf-c/Makefile: 1.22
872file      src/external/bsd/dhcpcd/sbin/dhcpcd/Makefile: 1.49
873file      src/tests/lib/libc/misc/Makefile: 1.5
874
875descr     Disable optimization on tc.c, logerr.c, ubsan.c crashes:
876          lib/libLLVMCodeGen/../../llvm/../../external/apache2/llvm/lib/..\
877          /dist/llvm/include/llvm/CodeGen/MachineFrameInfo.h", line 495, \
878          function "__int64_t llvm::MachineFrameInfo::getObjectOffset(int) const"
879kcah
880
881port      m68k
882hack      compile aes_ccm_tag() with -O0
883cdate     Mon Aug 10 06:27:29 UTC 2020
884mdate     Wed Aug 10 00:00:00 UTC 2022
885who       rin
886file      src/sys/crypto/aes/aes_ccm.c: 1.5
887descr     GCC 9.4 and 8.3 miscompile aes_ccm_tag() for m68k with optimization
888          level -O[12], which results in failure in aes_ccm_selftest().
889          For 9.4, -O0 and -O1 work but -O2 fails for amiga (A1200, 68060) and
890          mac68k (Quadra 840AV, 68040). Whereas -O0 and -O2 work but -O1 fails
891          for sun3 (TME, 68020 emulator) and sun2 (TME, 68010 emulator).
892          aes_ccm_selftest() still fails with GCC 10.4 and -O2.
893kcah
894
895port      sh3
896
897          hack      gcc9-sh3-lint
898          cdate     Tue Jun 22 14:59:52 CEST 2021
899          mdate     Mon Jul  5 12:34:57 CEST 2021
900          who       hgutch
901          file      external/gpl3/gcc/dist/gcc/config/sh/sh.md 1.2
902                    external/gpl3/gcc.old/dist/gcc/config/sh/sh.md 1.11
903          descr
904                    The in-tree gcc 9/gcc 10 crashes with an internal
905                    invalid opcode exception when using any kind of
906                    optimization on lex.c in usr.bin/xlint/lint .  This
907                    was introduced apparently unintendedly in gcc when
908                    addressing a different issue.  Rather than disabling
909                    optimization for lex.c, instead revert the change to
910                    gcc.  The bug report upstream has been updated to
911                    reflect the exact breakage.
912
913                    https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101177
914kcah
915
916port      arm
917hack      compile t_sig_backtrace with -fno-omit-frame-pointer for arm
918cdate     Tue Nov 23 23:24:37 UTC 2021
919mdate     Tue Nov 23 23:24:37 UTC 2021
920who       thorpej
921file      src/tests/lib/libexecinfo/Makefile: 1.8
922file      src/tests/lib/libexecinfo/t_sig_backtrace: 1.2
923descr     Unit test fails to pass unless t_sig_backtrace.c is compiled
924          with -fno-omit-frame-pointer and -DNOINLINE_HACK.
925kcah
926
927hack      alpha gcc error in lint
928cdate     2022/04/10 13:21:34
929who       martin
930port      alpha, vax
931file      usr.bin/xlint/Makefile.inc: 1.23, 1.25
932pr        56789
933descr
934          Compiling lint with -ftrapv fails with an internal
935          gcc compiler error.
936
937          https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105209
938
939          Supposedly fixed in gcc 11 or newer.
940kcah
941
942hack      compile copy{in,out}() for ibm4xx with -O0 for clang
943cdate     Mon Sep 12 08:06:36 UTC 2022
944who       rin
945port      evbppc
946file      sys/arch/powerpc/ibm4xx/trap.c: 1.99
947descr
948          clang 13.0.0 miscompiles copy{in,out}() with -O[12]. As a result,
949          kernel cannot execute /sbin/init.
950kcah
951
952hack      openssl: Disable ec_nistp_64_gcc_128 on aarch64eb
953cdate     Sat Jul  8 23:54:27 UTC 2023
954who       rin
955port      aarch64eb
956file      src/crypto/external/bsd/openssl/lib/libcrypto/arch/aarch64/ec.inc : 1.4
957descr
958          As described in upstream document:
959          https://github.com/openssl/openssl/blob/master/INSTALL.md#enable-ec_nistp_64_gcc_128
960          This feature (for LP64) does not support big-endian machines.
961          Note that sparc64 does not use this (port-sparc64/57472).
962kcah
963
964hack      GCC: Disable "-Warray-bounds" for x86 curcpu() and curlwp()
965cdate     Mon Sep  4 13:59:32 PDT 2023
966who       mrg
967port      i386 amd64
968file      src/sys/arch/amd64/include/cpu.h : 1.71
969file      src/sys/arch/i386/include/cpu.h : 1.184
970descr
971          These functions trigger eg:
972          ./machine/cpu.h:57:9: error: array subscript 0 is outside array bounds of 'struct cpu_info * const[0]' [-Werror=array-bounds]
973             56 |         __asm("movq %%gs:%1, %0" :
974          and can't easily be worked around.
975kcah
976
977hack      ctfconvert/gcc: disable gcc dwarf-4 generation
978cdate     Thu Apr  4 19:51:05 EDT 2024
979who       christos
980file      src/external/mit/xorg/lib/gallium.old/Makefile : 1.9
981descr
982          Some files create dwarf info that our ctfmerge can't handle.
983          We downgrade dwarf generation to version 3 which works.
984kcah
985
986hack      ia64: work around feclearexcept/fetestexcept compiler bug
987cdate     Sun May  5 23:06:10 UTC 2024
988who       riastradh
989file      tests/lib/libm/t_fe_round.c
990descr
991          Without judiciously placed __insn_barrier, we get:
992          /tmp//ccJayu9g.s:2793: Warning: Use of 'mov.m' violates RAW dependency 'AR[FPSR].sf0.flags' (impliedf)
993          /tmp//ccJayu9g.s:2793: Warning: Only the first path encountering the conflict is reported
994          /tmp//ccJayu9g.s:2757: Warning: This is the location of the conflicting usage
995kcah
996
997hack      m68k: work around stack protector m68k compiler bug
998cdate     Thu Jun  6 15:53:21 PDT 2024
999udate     Tue May  6 13:00:40 UTC 2025
1000port      m68k
1001who       mrg, rin
1002file      lib/libc/stdlib/strsuftoll.c : 1.10
1003file      lib/libc/citrus/citrus_module.c : 1.14
1004file      crypto/external/bsd/openssl/lib/libcrypto/blake2.inc : 1.3
1005file      crypto/external/bsd/openssl/lib/libcrypto/sha.inc : 1.8
1006file      external/mit/xorg/lib/freetype/Makefile : 1.26
1007file      external/mit/xorg/lib/gallium/Makefile : 1.56
1008file      external/mit/xorg/lib/libXfont2/Makefile : 1.13
1009descr
1010          With GCC 12, strsuftoll() triggers an stack protector issue
1011          that does not appear to be valid.  _citrus_find_getops() does
1012          the same.  They both have minimal stack usage themselves and
1013          I suspect a GCC bug.
1014          Other cases are less well studied.
1015kcah
1016
1017hack      gcc: work around alignment limitations in ld.elf_so
1018cdate     Mon Jun 17 23:35:52 UTC 2024
1019who       riastradh
1020file      external/gpl3/gcc/dist/libsanitizer/tsan/tsan_interceptors_posix.cpp : 1.4
1021file      src/external/gpl3/gcc/dist/libsanitizer/tsan/tsan_rtl.cpp : 1.4
1022file      external/gpl3/gcc/dist/libsanitizer/tsan/tsan_rtl.h : 1.5
1023descr
1024          ld.elf_so only supports 2*pointer-aligned objects (typically
1025          8- or 16-byte) in thread-local storage, but tsan expects
1026          cacheline-aligned objects (typically >=64-byte).  To work
1027          around this, allocate n + 63 bytes and pick whichever pointer
1028          in that interval is aligned (PR lib/58349).
1029kcah
1030