Get repository to build with GCC 11

See #594
This commit is contained in:
Justine Tunney 2022-09-13 04:14:20 -07:00
parent 446a1f7c5a
commit 06f9a5b627
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
34 changed files with 115 additions and 51 deletions

View file

@ -61,13 +61,19 @@
SHELL = build/bootstrap/cocmd.com
HOSTS ?= freebsd openbsd netbsd rhel7 rhel5 win10 xnu
MAKEFLAGS += --no-builtin-rules
MAKEFLAGS += -j --no-builtin-rules
.SUFFIXES:
.DELETE_ON_ERROR:
.FEATURES: output-sync
.PHONY: all o bins check test depend tags
ifneq ($(m),)
ifeq ($(MODE),)
MODE := $(m)
endif
endif
all: o
o: o/$(MODE)

View file

@ -27,7 +27,7 @@ wget https://justine.lol/cosmopolitan/cosmopolitan-amalgamation-2.0.1.zip
unzip cosmopolitan-amalgamation-2.0.1.zip
printf 'main() { printf("hello world\\n"); }\n' >hello.c
gcc -g -Os -static -nostdlib -nostdinc -fno-pie -no-pie -mno-red-zone \
-fno-omit-frame-pointer -pg -mnop-mcount -mno-tls-direct-seg-refs \
-fno-omit-frame-pointer -pg -mnop-mcount -mno-tls-direct-seg-refs -gdwarf-4 \
-o hello.com.dbg hello.c -fuse-ld=bfd -Wl,-T,ape.lds -Wl,--gc-sections \
-include cosmopolitan.h crt.o ape-no-modify-self.o cosmopolitan.a
objcopy -S -O binary hello.com.dbg hello.com
@ -100,7 +100,7 @@ heavyweight features like tracing to your binaries by default. In that
case, you may want to consider using our build system:
```sh
make -j8 MODE=tiny
make m=tiny
```
Which will cause programs such as `hello.com` and `life.com` to shrink
@ -155,7 +155,7 @@ cd cosmopolitan
This will build the entire repository and run all the tests:
```sh
build/bootstrap/make.com -j16
build/bootstrap/make.com
o//examples/hello.com
find o -name \*.com | xargs ls -rShal | less
```
@ -174,7 +174,7 @@ having minimal deterministic builds. For example, if you wanted to build
only hello.com then you could do that as follows:
```sh
build/bootstrap/make.com -j16 o//examples/hello.com
build/bootstrap/make.com o//examples/hello.com
```
Sometimes it's desirable to build a subset of targets, without having to
@ -183,7 +183,7 @@ directory name. For example, if you wanted to build only the targets and
subtargets of the chibicc package including its tests, you would say:
```sh
build/bootstrap/make.com -j16 o//third_party/chibicc
build/bootstrap/make.com o//third_party/chibicc
o//third_party/chibicc/chibicc.com --help
```
@ -191,18 +191,19 @@ Cosmopolitan provides a variety of build modes. For example, if you want
really tiny binaries (as small as 12kb in size) then you'd say:
```sh
build/bootstrap/make.com -j16 MODE=tiny
build/bootstrap/make.com m=tiny
```
Here's some other build modes you can try:
```sh
build/bootstrap/make.com -j16 MODE=dbg # asan + ubsan + debug
build/bootstrap/make.com -j16 MODE=asan # production memory safety
build/bootstrap/make.com -j16 MODE=opt # -march=native optimizations
build/bootstrap/make.com -j16 MODE=rel # traditional release binaries
build/bootstrap/make.com -j16 MODE=optlinux # optimal linux-only performance
build/bootstrap/make.com -j16 MODE=tinylinux # tiniest linux-only 4kb binaries
build/bootstrap/make.com m=dbg # asan + ubsan + debug
build/bootstrap/make.com m=asan # production memory safety
build/bootstrap/make.com m=opt # -march=native optimizations
build/bootstrap/make.com m=rel # traditional release binaries
build/bootstrap/make.com m=optlinux # optimal linux-only performance
build/bootstrap/make.com m=fastbuild # build 28% faster w/o debugging
build/bootstrap/make.com m=tinylinux # tiniest linux-only 4kb binaries
```
For further details, see [//build/config.mk](build/config.mk).

View file

@ -282,6 +282,28 @@ TARGET_ARCH ?= \
-msse3
endif
# GCC11 Mode
# https://justine.lol/compilers/x86_64-linux-musl__x86_64-linux-musl__g++-11.2.0.tar.xz
ifeq ($(MODE), gcc11)
.UNVEIL += rx:/opt/gcc11
CONFIG_CCFLAGS += $(BACKTRACES) $(FTRACE) -DSYSDEBUG -O2
AS = /opt/gcc11/bin/x86_64-linux-musl-as
CC = /opt/gcc11/bin/x86_64-linux-musl-gcc
CXX = /opt/gcc11/bin/x86_64-linux-musl-g++
CXXFILT = /opt/gcc11/bin/x86_64-linux-musl-c++filt
LD = /opt/gcc11/bin/x86_64-linux-musl-ld.bfd
NM = /opt/gcc11/bin/x86_64-linux-musl-nm
GCC = /opt/gcc11/bin/x86_64-linux-musl-gcc
STRIP = /opt/gcc11/bin/x86_64-linux-musl-strip
OBJCOPY = /opt/gcc11/bin/x86_64-linux-musl-objcopy
OBJDUMP = /opt/gcc11/bin/x86_64-linux-musl-objdump
ADDR2LINE = /opt/gcc11/bin/x86_64-linux-musl-addr2line
CONFIG_CCFLAGS += $(BACKTRACES) $(FTRACE) -O2 -Wno-stringop-overread
CONFIG_CFLAGS += -Wno-old-style-definition
CONFIG_CPPFLAGS += -DNDEBUG -DSYSDEBUG
TARGET_ARCH ?= -msse3
endif
# LLVM Mode
ifeq ($(MODE), llvm)
TARGET_ARCH ?= -msse3

View file

@ -148,6 +148,7 @@ DEFAULT_CCFLAGS = \
DEFAULT_OFLAGS = \
-g \
-gdwarf-4 \
-gdescribe-dies
DEFAULT_COPTS = \

View file

@ -30,7 +30,7 @@
* @see ttyconfig(), ttyrestore()
*/
int ttyconfig(int ttyfd, ttyconf_f fn, int64_t arg,
const struct termios *opt_out_oldconf) {
struct termios *opt_out_oldconf) {
struct termios conf[2];
if (tcgetattr(ttyfd, &conf[0]) != -1 &&
fn(memcpy(&conf[1], &conf[0], sizeof(conf[0])), arg) != -1 &&

View file

@ -44,7 +44,7 @@ int ttysendtitle(int, const char *, const struct TtyIdent *);
int ttyident(struct TtyIdent *, int, int);
void ttyidentclear(struct TtyIdent *);
char *ttydescribe(char *, size_t, const struct TtyIdent *);
int ttyconfig(int, ttyconf_f, int64_t, const struct termios *);
int ttyconfig(int, ttyconf_f, int64_t, struct termios *);
int ttyrestore(int, const struct termios *);
int ttysetrawdeadline(struct termios *, int64_t);
int ttysetrawmode(struct termios *, int64_t);

View file

@ -17,11 +17,11 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/calls.h"
#include "libc/intrin/strace.internal.h"
#include "libc/calls/syscall-nt.internal.h"
#include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/sysv/errfuns.h"
/**

View file

@ -5,18 +5,18 @@
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
int __sys_utimensat(int, const char *, const struct timespec *, int) hidden;
int __sys_utimensat(int, const char *, const struct timespec[2], int) hidden;
int sys_clock_getres(int, struct timespec *) hidden;
int sys_clock_gettime(int, struct timespec *) hidden;
int sys_clock_gettime_nt(int, struct timespec *) hidden;
int sys_clock_gettime_xnu(int, struct timespec *) hidden;
int sys_futimens(int, const struct timespec *) hidden;
int sys_futimens(int, const struct timespec[2]) hidden;
int sys_nanosleep(const struct timespec *, struct timespec *) hidden;
int sys_nanosleep_nt(const struct timespec *, struct timespec *) hidden;
int sys_nanosleep_xnu(const struct timespec *, struct timespec *) hidden;
int sys_utimensat(int, const char *, const struct timespec *, int) hidden;
int sys_utimensat_nt(int, const char *, const struct timespec *, int) hidden;
int sys_utimensat_xnu(int, const char *, const struct timespec *, int) hidden;
int sys_utimensat(int, const char *, const struct timespec[2], int) hidden;
int sys_utimensat_nt(int, const char *, const struct timespec[2], int) hidden;
int sys_utimensat_xnu(int, const char *, const struct timespec[2], int) hidden;
const char *DescribeTimespec(char[45], int, const struct timespec *);
#define DescribeTimespec(rc, ts) DescribeTimespec(alloca(45), rc, ts)

View file

@ -21,7 +21,7 @@
#include "libc/testlib/testlib.h"
bool testlib_strcaseequals(size_t cw, const void *s1, const void *s2) {
return testlib_strncaseequals(cw, s1, s2, SIZE_MAX);
return testlib_strncaseequals(cw, s1, s2, LONG_MAX);
}
bool testlib_strncaseequals(size_t cw, const void *s1, const void *s2,

View file

@ -21,7 +21,7 @@
#include "libc/testlib/testlib.h"
bool testlib_strequals(size_t cw, const void *s1, const void *s2) {
return testlib_strnequals(cw, s1, s2, SIZE_MAX);
return testlib_strnequals(cw, s1, s2, LONG_MAX);
}
bool testlib_strnequals(size_t cw, const void *s1, const void *s2, size_t n) {

View file

@ -69,7 +69,7 @@
static char buf_asctime[MAX_ASCTIME_BUF_SIZE];
char *
asctime_r(register const struct tm *timeptr, char *buf)
asctime_r(register const struct tm *timeptr, char buf[hasatleast 26])
{
register const char * wn;
register const char * mn;

View file

@ -2,7 +2,7 @@
#include "libc/time/struct/tm.h"
#include "libc/time/time.h"
char *ctime_r(const time_t *timep, char *buf) {
char *ctime_r(const time_t *timep, char buf[hasatleast 26]) {
struct tm mytm;
struct tm *tmp = localtime_r(timep, &mytm);
return tmp ? asctime_r(tmp, buf) : NULL;

View file

@ -18,7 +18,7 @@ struct tm {
};
char *asctime(const struct tm *);
char *asctime_r(const struct tm *, char[hasatleast 64]);
char *asctime_r(const struct tm *, char[hasatleast 26]);
char *iso8601(char[hasatleast 20], struct tm *);
char *strptime(const char *, const char *, struct tm *);
int64_t mktime(struct tm *);

View file

@ -18,7 +18,7 @@ extern long timezone;
extern int daylight;
char *ctime(const int64_t *);
char *ctime_r(const int64_t *, char[hasatleast 64]);
char *ctime_r(const int64_t *, char[hasatleast 26]);
double difftime(int64_t, int64_t) dontthrow pureconst;
extern long double (*nowl)(void);
int64_t clock(void);

View file

@ -29,7 +29,7 @@ char buf[6] = {0};
struct rlimit rlim = {0, 10};
TEST(pipe, efault) {
EXPECT_SYS(EFAULT, -1, pipe(0));
EXPECT_SYS(EFAULT, -1, pipe(VEIL("r", (void *)0)));
}
TEST(pipe, einval) {

View file

@ -16,6 +16,7 @@
#define _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
#define _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS
#define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION
#define _LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE
#if defined(_MSC_VER) && !defined(__clang__)
# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)

View file

@ -55,8 +55,10 @@ template unsigned __sort5<__less<long double>&, long double*>(long double*, long
#ifndef _LIBCPP_HAS_NO_THREADS
_LIBCPP_SAFE_STATIC static __libcpp_mutex_t __rs_mut = _LIBCPP_MUTEX_INITIALIZER;
#endif
unsigned __rs_default::__c_ = 0;
#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE) \
|| defined(_LIBCPP_BUILDING_LIBRARY)
unsigned __rs_default::__c_ = 0;
__rs_default::__rs_default()
{
#ifndef _LIBCPP_HAS_NO_THREADS
@ -64,12 +66,10 @@ __rs_default::__rs_default()
#endif
__c_ = 1;
}
__rs_default::__rs_default(const __rs_default&)
{
++__c_;
}
__rs_default::~__rs_default()
{
#ifndef _LIBCPP_HAS_NO_THREADS
@ -79,13 +79,13 @@ __rs_default::~__rs_default()
--__c_;
#endif
}
__rs_default::result_type
__rs_default::operator()()
{
static mt19937 __rs_g;
return __rs_g();
}
#endif
__rs_default
__rs_get()

View file

@ -14,23 +14,25 @@
namespace std {
_LIBCPP_SAFE_STATIC static std::terminate_handler __terminate_handler;
_LIBCPP_SAFE_STATIC static std::unexpected_handler __unexpected_handler;
#if _LIBCPP_STD_VER <= 14 || \
defined(_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS) || \
defined(_LIBCPP_BUILDING_LIBRARY)
_LIBCPP_SAFE_STATIC static std::unexpected_handler __unexpected_handler;
// libcxxrt provides implementations of these functions itself.
unexpected_handler set_unexpected(unexpected_handler func) _NOEXCEPT {
return __libcpp_atomic_exchange(&__unexpected_handler, func);
}
unexpected_handler get_unexpected() _NOEXCEPT {
return __libcpp_atomic_load(&__unexpected_handler);
}
_LIBCPP_NORETURN
void unexpected() {
(*get_unexpected())();
// unexpected handler should not return
terminate();
}
#endif
terminate_handler set_terminate(terminate_handler func) _NOEXCEPT {
return __libcpp_atomic_exchange(&__terminate_handler, func);

View file

@ -427,7 +427,9 @@ eval_makefile (const char *filename, unsigned short flags)
fclose (ebuf.fp);
free (ebuf.bufstart);
alloca (0);
/* [jart] breaks gcc11 (also wat) */
void *volatile wat = alloca (0);
errno = 0;
return deps;
@ -469,7 +471,8 @@ eval_buffer (char *buffer, const floc *flocp)
reading_file = curfile;
alloca (0);
/* [jart] breaks gcc11 (also wat) */
void *volatile wat = alloca (0);
}
/* Check LINE to see if it's a variable assignment or undefine.
@ -2495,7 +2498,8 @@ find_percent_cached (const char **string)
if (! new)
{
slen = strlen (*string);
new = alloca (slen + 1);
/* [jart] can't prove alloca() isn't returned; let's just leak */
new = malloc (slen + 1);
memcpy (new, *string, slen + 1);
p = new + (p - *string);
*string = new;

View file

@ -322,7 +322,7 @@ update_file (struct file *file, unsigned int depth)
check_renamed (f);
/* Clean up any alloca() used during the update. */
alloca (0);
void *volatile wat = alloca (0);
/* If we got an error, don't bother with double_colon etc. */
if (new && !keep_going_flag)

View file

@ -29,7 +29,7 @@
* @note words are host endian while array is little endian
* @mayalias
*/
void (*Mul4x4)(uint64_t C[8], const uint64_t A[4], const uint64_t B[4]);
void (*Mul4x4)(uint64_t C[16], const uint64_t A[8], const uint64_t B[8]);
static textstartup void Mul4x4Init()
{
@ -38,7 +38,7 @@ static textstartup void Mul4x4Init()
const void *const Mul4x4Ctor[] initarray = {Mul4x4Init};
void Mul4x4Pure(uint64_t C[8], const uint64_t A[4], const uint64_t B[4])
void Mul4x4Pure(uint64_t C[16], const uint64_t A[8], const uint64_t B[8])
{
uint128_t t;
uint64_t h, c1, c2, c3;

View file

@ -2699,7 +2699,7 @@ void test_ssl_message_queue_insufficient_buffer_wrapper( void ** params )
void test_ssl_message_mock_uninitialized( )
{
enum { MSGLEN = 10 };
unsigned char message[MSGLEN], received[MSGLEN];
unsigned char message[MSGLEN] = {0}, received[MSGLEN];
mbedtls_mock_socket client, server;
mbedtls_test_message_queue server_queue, client_queue;
mbedtls_test_message_socket_context server_context, client_context;

View file

@ -38,6 +38,10 @@
#include "third_party/python/Modules/_decimal/libmpdec/typearith.h"
/* clang-format off */
#if __GNUC__ >= 11
#pragma GCC diagnostic ignored "-Wmisleading-indentation"
#endif
asm(".ident\t\"\\n\\n\
libmpdec (BSD-2)\\n\
Copyright 2008-2016 Stefan Krah\"");

View file

@ -90,7 +90,7 @@ NS(XmlInitEncoding)(INIT_ENCODING *p, const ENCODING **encPtr,
static const ENCODING *
NS(findEncoding)(const ENCODING *enc, const char *ptr, const char *end) {
# define ENCODING_MAX 128
char buf[ENCODING_MAX];
char buf[ENCODING_MAX] = {0}; /* [jart] wut */
char *p = buf;
int i;
XmlUtf8Convert(enc, &ptr, end, &p, p + ENCODING_MAX - 1);

View file

@ -24,6 +24,10 @@
*/
#include "third_party/sqlite3/sqliteInt.inc"
#if __GNUC__ >= 11
#pragma GCC diagnostic ignored "-Wmisleading-indentation"
#endif
/* clang-format off */
#ifndef SQLITE_OMIT_SHARED_CACHE
@ -4230,7 +4234,7 @@ void sqlite3DefaultRowEst(Index *pIdx){
if( x<99 ){
pIdx->pTable->nRowLogEst = x = 99;
}
if( pIdx->pPartIdxWhere!=0 ) x -= 10; assert( 10==sqlite3LogEst(2) );
if( pIdx->pPartIdxWhere!=0 ) x -= 10; /*assert( 10==sqlite3LogEst(2) );*/
a[0] = x;
/* Estimate that a[1] is 10, a[2] is 9, a[3] is 8, a[4] is 7, a[5] is

View file

@ -14170,10 +14170,13 @@ static int sqlite3Fts5IndexQuery(
/* If the QUERY_SCAN flag is set, all other flags must be clear. */
assert( (flags & FTS5INDEX_QUERY_SCAN)==0 || flags==FTS5INDEX_QUERY_SCAN );
/* [jart] what is with these gcc11 warnings */
void *MemCpy(void *, const void *, size_t) asm("memcpy");
if( sqlite3Fts5BufferSize(&p->rc, &buf, nToken+1)==0 ){
int iIdx = 0; /* Index to search */
int iPrefixIdx = 0; /* +1 prefix index */
if( nToken ) memcpy(&buf.p[1], pToken, nToken);
if( nToken ) MemCpy(&buf.p[1], pToken, nToken);
/* Figure out which index to search and set iIdx accordingly. If this
** is a prefix query for which there is no prefix index, set iIdx to

View file

@ -20,6 +20,10 @@
#include "third_party/sqlite3/whereInt.inc"
/* clang-format off */
#if __GNUC__ >= 11
#pragma GCC diagnostic ignored "-Wmisleading-indentation"
#endif
/*
** Extra information appended to the end of sqlite3_index_info but not
** visible to the xBestIndex function, at least not directly. The

View file

@ -891,7 +891,7 @@ static Bool CompareColors( const int rgbBG[3], const int rgbFG[3] )
* blue = 5.
*********************************************************************/
static Bool GetRgb( ctmbstr color, int rgb[] )
static Bool GetRgb( ctmbstr color, int rgb[3] )
{
uint x;

View file

@ -14,6 +14,10 @@
#include "libc/fmt/fmt.h"
#include "third_party/tidy/utf8.h"
#if __GNUC__ >= 11 /* [jart] this one looks legit */
#pragma GCC diagnostic ignored "-Wmisleading-indentation"
#endif
/*
Bind attribute types to procedures to check values.
You can add new procedures for better validation

View file

@ -75,6 +75,10 @@
#include "third_party/unzip/unzvers.h"
#include "third_party/unzip/globals.h"
#if __GNUC__ >= 11 /* [jart] worth looking into */
#pragma GCC diagnostic ignored "-Wrestrict"
#endif
#ifndef WINDLL /* The WINDLL port uses windll/windll.c instead... */
/***************************/

View file

@ -59,6 +59,10 @@ $(THIRD_PARTY_UNZIP_A_OBJS): private \
-DHAVE_TERMIOS_H \
-DNO_LCHMOD
$(THIRD_PARTY_UNZIP_A_OBJS): private \
OVERRIDE_CFLAGS += \
$(OLD_CODE)
THIRD_PARTY_UNZIP_COMS = o/$(MODE)/third_party/unzip/unzip.com
THIRD_PARTY_UNZIP_BINS = $(THIRD_PARTY_UNZIP_COMS) $(THIRD_PARTY_UNZIP_COMS:%=%.dbg)
THIRD_PARTY_UNZIP_LIBS = $(foreach x,$(THIRD_PARTY_UNZIP_ARTIFACTS),$($(x)))

View file

@ -46,7 +46,7 @@ void XlatLinuxToTermios(struct termios *, const struct termios_bits *);
void XlatTermiosToLinux(struct termios_bits *, const struct termios *);
void XlatWinsizeToLinux(struct winsize_bits *, const struct winsize *);
void XlatSigsetToLinux(uint8_t[8], const sigset_t *);
void XlatLinuxToSigset(sigset_t *, const uint8_t[]);
void XlatLinuxToSigset(sigset_t *, const uint8_t[8]);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */

View file

@ -169,7 +169,7 @@
((eq arg 8) "llvm")
(default default)
((cosmo-intest) "dbg")
(t "")))
(t "fastbuild")))
(defun cosmo--make-suffix (arg)
(cond ((eq arg 9) ".chibicc")

View file

@ -12,13 +12,13 @@ extern long magikarp_latency_;
extern long ycbcr2rgb_latency_;
void Y2Rgb(long yn, long xn, unsigned char[restrict 3][yn][xn], long yys,
long yxs, const unsigned char[restrict yys][yxs], const int[4][4],
long yxs, const unsigned char[restrict yys][yxs], const int[8][4],
const unsigned char[256]);
void YCbCr2Rgb(long yn, long xn, unsigned char[restrict 3][yn][xn], long yys,
long yxs, const unsigned char[restrict yys][yxs], long cys,
long cxs, const unsigned char[restrict cys][cxs],
const unsigned char[restrict cys][cxs], const int[4][4],
const int[3][4], const unsigned char[256]);
const unsigned char[restrict cys][cxs], const int[8][4],
const int[6][4], const unsigned char[256]);
void YCbCrFree(struct YCbCr **);
void YCbCrInit(struct YCbCr **, bool, int, double, const double[3],