From 8375aac0ff3173c8bd90045e0019cb3b281a85bc Mon Sep 17 00:00:00 2001 From: Per Lundberg Date: Tue, 26 Sep 2017 20:43:22 +0300 Subject: [PATCH 01/11] Travis: Support newer gcc versions In fact, run on both gcc 4.9, 5, 6 and 7. This is probably overkill in the long run. If it turns out to be a maintenance nightmare, we can drop one or more of these easily. --- .travis.yml | 75 ++++++++++++++++++++++++++++++++++---- storm/raspberrypi/Rakefile | 2 +- 2 files changed, 68 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index 69551ef6..21452469 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,21 +1,80 @@ sudo: required dist: trusty + +matrix: + include: + - os: linux + addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - gcc-4.9 + - gcc-4.9-multilib + env: + - MATRIX_EVAL="CC=gcc-4.9 && ARCH=x86" + + - os: linux + addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - gcc-5 + - gcc-5-multilib + env: + - MATRIX_EVAL="CC=gcc-5 && ARCH=x86" + + - os: linux + addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - gcc-6 + - gcc-6-multilib + env: + - MATRIX_EVAL="CC=gcc-6 && ARCH=x86" + + - os: linux + addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - gcc-7 + - gcc-7-multilib + env: + - MATRIX_EVAL="CC=gcc-7 && ARCH=x86" + + - os: linux + addons: + apt: + packages: + - gcc-arm-none-eabi + env: + - MATRIX_EVAL="ARCH=raspberrypi" + +addons: + apt: + packages: + +before_install: + - eval "${MATRIX_EVAL}" + - export CC + - export ARCH + before_script: - sudo apt-get update - sudo apt-get install dosfstools - gcc-arm-none-eabi - gcc-multilib genisoimage grub mtools nasm - ./install_cmocka.sh + +# Tests are disabled for now since cmocka don't work on Trusty Tahr. script: - bundle exec rubocop - - ARCH=raspberrypi rake - default - clean - # Tests are disabled for now since cmocka don't work on Trusty Tahr. - - ARCH=x86 CC=gcc rake - default + - rake default diff --git a/storm/raspberrypi/Rakefile b/storm/raspberrypi/Rakefile index 2002bb53..c9445245 100644 --- a/storm/raspberrypi/Rakefile +++ b/storm/raspberrypi/Rakefile @@ -13,7 +13,7 @@ OUTPUT = 'libstorm_raspberrypi.a'.freeze GENERIC_OUTPUT = '../generic/libstorm_generic.a'.freeze KERNEL_OUTPUT = 'storm'.freeze -LDFLAGS = '-nostartfiles'.freeze +LDFLAGS = '-nostdlib'.freeze task default: [:banner, :prepare, :storm] + objects From d4e1e65f7f685e5662d7c1de417c4daacc482365 Mon Sep 17 00:00:00 2001 From: Per Lundberg Date: Tue, 26 Sep 2017 21:36:23 +0300 Subject: [PATCH 02/11] Attempt to fix warning w/ gcc 6 and 7. --- storm/x86/dma.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/storm/x86/dma.c b/storm/x86/dma.c index f470af87..8d1c396b 100644 --- a/storm/x86/dma.c +++ b/storm/x86/dma.c @@ -20,20 +20,20 @@ #define DMA_CHANNEL_CASCADE 4 // Controller registers. -static const unsigned int dma_controller[NUMBER_OF_CONTROLLERS] = -{ - 0x08, 0xD0 -}; - -static const unsigned int dma_master_reset[NUMBER_OF_CONTROLLERS] = -{ - 0x0D, 0xDA -}; - -static const unsigned int dma_master_mask[NUMBER_OF_CONTROLLERS] = -{ - 0x0F, 0xDE -}; +// static const unsigned int dma_controller[NUMBER_OF_CONTROLLERS] = +// { +// 0x08, 0xD0 +// }; + +// static const unsigned int dma_master_reset[NUMBER_OF_CONTROLLERS] = +// { +// 0x0D, 0xDA +// }; + +// static const unsigned int dma_master_mask[NUMBER_OF_CONTROLLERS] = +// { +// 0x0F, 0xDE +// }; static const unsigned int dma_mask[NUMBER_OF_CONTROLLERS] = { From b77ba74509b28235449857de1edd2cf862dc1014 Mon Sep 17 00:00:00 2001 From: Per Lundberg Date: Tue, 26 Sep 2017 22:17:19 +0300 Subject: [PATCH 03/11] Attempt to fix gcc-7 compile error Inspired by this: https://stackoverflow.com/questions/47981/how-do-you-set-clear-and-toggle-a-single-bit --- storm/include/storm/generic/bit.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/storm/include/storm/generic/bit.h b/storm/include/storm/generic/bit.h index 9f243a33..3aaa3eab 100644 --- a/storm/include/storm/generic/bit.h +++ b/storm/include/storm/generic/bit.h @@ -1,14 +1,16 @@ // Abstract: Bit functions. // Author: Per Lundberg -// © Copyright 1999-2000, 2013 chaos development. +// © Copyright 1999-2000 chaos development +// © Copyright 2013 chaos development +// © Copyright 2017 chaos development #pragma once #if (defined __i386__) || (defined __i486__) || (defined __i586__) || (defined __i686__) // Little-endian system. # define BIT_SET(a, b) ((a) |= (1 << (b))) -# define BIT_CLEAR(a, b) ((a) &= !(1 << (b))) +# define BIT_CLEAR(a, b) ((a) &= ~(1 << (b))) # define BIT_GET(a, b) ((a) & (1 << (b)) ? 1 : 0) # define BIT_IN_BYTES(a) ((a) % 8 != 0 ? (a) / 8 + 1 : (a) / 8) From 28ff222383d7b687e770eccc9a6c8e13f8ebefe6 Mon Sep 17 00:00:00 2001 From: Per Lundberg Date: Wed, 27 Sep 2017 00:19:33 +0300 Subject: [PATCH 04/11] TIL: Explicit case fallthrough More details: https://developers.redhat.com/blog/2017/03/10/wimplicit-fallthrough-in-gcc-7/ --- libraries/string/string.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libraries/string/string.c b/libraries/string/string.c index 71b033f9..58665fce 100644 --- a/libraries/string/string.c +++ b/libraries/string/string.c @@ -538,6 +538,10 @@ return_type string_print_va(char *output, const char *format_string, case 'X': { flags |= UPPER_HEX; + + // Falls through by design. (Can't use __attribute__ ((fallthrough)), since it breaks on gcc < 7.) + // + /* @fallthrough@ */ } case 'x': From 2b7e3fdce2b8d5c0301c7542f31c8a837c6ad87f Mon Sep 17 00:00:00 2001 From: Per Lundberg Date: Wed, 27 Sep 2017 12:15:30 +0300 Subject: [PATCH 05/11] Attempted workaround for -Wimplicit-fallthrough The comment approach did not work for me; the warning level seemed not to be 3 as it ought to be. Maybe if we explicitly set it to 4, things will work. --- rakelib/common_settings.rake | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/rakelib/common_settings.rake b/rakelib/common_settings.rake index 0e9e7192..96a3d0c3 100644 --- a/rakelib/common_settings.rake +++ b/rakelib/common_settings.rake @@ -28,7 +28,10 @@ else AR = ENV['AR'] || 'ar' AR_TARGET = '--target=elf32-i386'.freeze NASM = 'nasm'.freeze - ARCH_CFLAGS = '-m32'.freeze + + extra_cflags = '-m32' + extra_cflags += ' -Wimplicit-fallthrough=4' if CC =~ /gcc-7/ + ARCH_CFLAGS = extra_cflags.freeze elsif TARGET_ARCH == 'raspberrypi' CC = ENV['CC'] || 'arm-none-eabi-gcc' AR = ENV['AR'] || 'arm-none-eabi-ar' From c9bee782d9ea945d85a8dc0e6bad2b73a6e019ce Mon Sep 17 00:00:00 2001 From: Per Lundberg Date: Wed, 27 Sep 2017 15:46:07 +0300 Subject: [PATCH 06/11] ARCH_CFLAGS was only being used when compiling chaos. Should be used when compiling the libraries and servers also. --- rakelib/common_rules.rake | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/rakelib/common_rules.rake b/rakelib/common_rules.rake index e9a30d7f..06acc5a5 100644 --- a/rakelib/common_rules.rake +++ b/rakelib/common_rules.rake @@ -24,7 +24,7 @@ end rule '.o' => ['.S'] do |t| begin print((t.source + ' ').cyan) - command = "#{CC} -o #{t.name} #{CFLAGS} #{INCLUDES.join(' ')} -c #{t.source}" + command = "#{CC} -o #{t.name} #{cflags} #{INCLUDES.join(' ')} -c #{t.source}" sh command rescue puts "Error compiling #{t.source}. Full command line was: #{command}" @@ -44,6 +44,11 @@ rule '.o' => ['.asm'] do |t| end def cflags - flags = CFLAGS.join(' ') if CFLAGS.respond_to?(:join) - flags || CFLAGS + flags = if CFLAGS.respond_to?(:join) + CFLAGS.join(' ') + else + CFLAGS + end + + flags + ' ' + ARCH_CFLAGS end From 67f0782a5626dbbd11d1e953b4893741ead8150a Mon Sep 17 00:00:00 2001 From: Per Lundberg Date: Wed, 27 Sep 2017 15:53:48 +0300 Subject: [PATCH 07/11] Try level 3 instead. --- rakelib/common_settings.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rakelib/common_settings.rake b/rakelib/common_settings.rake index 96a3d0c3..24bf457f 100644 --- a/rakelib/common_settings.rake +++ b/rakelib/common_settings.rake @@ -30,7 +30,7 @@ else NASM = 'nasm'.freeze extra_cflags = '-m32' - extra_cflags += ' -Wimplicit-fallthrough=4' if CC =~ /gcc-7/ + extra_cflags += ' -Wimplicit-fallthrough=3' if CC =~ /gcc-7/ ARCH_CFLAGS = extra_cflags.freeze elsif TARGET_ARCH == 'raspberrypi' CC = ENV['CC'] || 'arm-none-eabi-gcc' From 2a5ad59112f07d223ca768b5ce8a4e96d0e6a735 Mon Sep 17 00:00:00 2001 From: Per Lundberg Date: Wed, 27 Sep 2017 16:02:56 +0300 Subject: [PATCH 08/11] One more try to get it working. --- rakelib/common_settings.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rakelib/common_settings.rake b/rakelib/common_settings.rake index 24bf457f..a1472c6f 100644 --- a/rakelib/common_settings.rake +++ b/rakelib/common_settings.rake @@ -30,7 +30,7 @@ else NASM = 'nasm'.freeze extra_cflags = '-m32' - extra_cflags += ' -Wimplicit-fallthrough=3' if CC =~ /gcc-7/ + extra_cflags += ' -Werror=implicit-fallthrough=3' if CC =~ /gcc-7/ ARCH_CFLAGS = extra_cflags.freeze elsif TARGET_ARCH == 'raspberrypi' CC = ENV['CC'] || 'arm-none-eabi-gcc' From ce8d3f7dfa9ec294438e5d91e7e1b3a303c888a8 Mon Sep 17 00:00:00 2001 From: Per Lundberg Date: Wed, 27 Sep 2017 19:17:11 +0300 Subject: [PATCH 09/11] Googled for -Wimplicit-fallthrough This should work. The commment must be outside of the block, if it exists... --- libraries/string/string.c | 5 ++--- rakelib/common_settings.rake | 5 +---- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/libraries/string/string.c b/libraries/string/string.c index 58665fce..2eead0ea 100644 --- a/libraries/string/string.c +++ b/libraries/string/string.c @@ -539,10 +539,9 @@ return_type string_print_va(char *output, const char *format_string, { flags |= UPPER_HEX; - // Falls through by design. (Can't use __attribute__ ((fallthrough)), since it breaks on gcc < 7.) - // - /* @fallthrough@ */ } + // Falls through by design. (Can't use __attribute__ ((fallthrough)), since it breaks on gcc < 7.) + // @fallthrough@ case 'x': { diff --git a/rakelib/common_settings.rake b/rakelib/common_settings.rake index a1472c6f..0e9e7192 100644 --- a/rakelib/common_settings.rake +++ b/rakelib/common_settings.rake @@ -28,10 +28,7 @@ else AR = ENV['AR'] || 'ar' AR_TARGET = '--target=elf32-i386'.freeze NASM = 'nasm'.freeze - - extra_cflags = '-m32' - extra_cflags += ' -Werror=implicit-fallthrough=3' if CC =~ /gcc-7/ - ARCH_CFLAGS = extra_cflags.freeze + ARCH_CFLAGS = '-m32'.freeze elsif TARGET_ARCH == 'raspberrypi' CC = ENV['CC'] || 'arm-none-eabi-gcc' AR = ENV['AR'] || 'arm-none-eabi-ar' From e48c30b1c1ed3fc4c750d3427e36bb9d46887375 Mon Sep 17 00:00:00 2001 From: Per Lundberg Date: Wed, 27 Sep 2017 20:23:42 +0300 Subject: [PATCH 10/11] One more futile attempt to get it working w/ gcc-7 --- libraries/string/string.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/string/string.c b/libraries/string/string.c index 2eead0ea..cc1b5071 100644 --- a/libraries/string/string.c +++ b/libraries/string/string.c @@ -541,8 +541,8 @@ return_type string_print_va(char *output, const char *format_string, } // Falls through by design. (Can't use __attribute__ ((fallthrough)), since it breaks on gcc < 7.) + // // @fallthrough@ - case 'x': { char string[9]; From 0b707bfb7e01d44f70b633da352cc4f67da3e26e Mon Sep 17 00:00:00 2001 From: Per Lundberg Date: Wed, 27 Sep 2017 21:02:39 +0300 Subject: [PATCH 11/11] One more try Inspired by https://github.com/ponylang/ponyc/issues/1581 --- libraries/string/string.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/string/string.c b/libraries/string/string.c index cc1b5071..17980fcb 100644 --- a/libraries/string/string.c +++ b/libraries/string/string.c @@ -542,7 +542,7 @@ return_type string_print_va(char *output, const char *format_string, } // Falls through by design. (Can't use __attribute__ ((fallthrough)), since it breaks on gcc < 7.) // - // @fallthrough@ + // fallthrough case 'x': { char string[9];