diff options
author | Luis Fernandez <luis.fernandez@ibm.com> | 2019-02-21 14:13:44 -0600 |
---|---|---|
committer | Daniel M. Crowell <dcrowell@us.ibm.com> | 2019-04-05 16:52:10 -0500 |
commit | 4995ec0ba6f15e03deb4b9ad1dc215f3f8993acb (patch) | |
tree | 35524433b3a4b268b12516cfdf2dd033688599b2 /src/build | |
parent | c8651104f00db7538147ab4cea9c9a3a8df5e500 (diff) | |
download | talos-hostboot-4995ec0ba6f15e03deb4b9ad1dc215f3f8993acb.tar.gz talos-hostboot-4995ec0ba6f15e03deb4b9ad1dc215f3f8993acb.zip |
HB Improvements: Fix compiler warnings on modern compilers
Resolve warnings when compiling with gcc 4.8. Compiled with GCC 7.3,
no more compile errors/warnings; build ends with caught exception from
linker. This commit compiles with GCC 8.2, no more error/warnings; except
for a linking warning.
Change-Id: Ib5d7c2b5bd350edc76ee2c7de96896154cd44420
RTC: 202716
Reviewed-on: http://rchgit01.rchland.ibm.com/gerrit1/72271
Reviewed-by: Nicholas E. Bofferding <bofferdn@us.ibm.com>
Reviewed-by: Ilya Smirnov <ismirno@us.ibm.com>
Tested-by: Jenkins Server <pfd-jenkins+hostboot@us.ibm.com>
Tested-by: FSP CI Jenkins <fsp-CI-jenkins+hostboot@us.ibm.com>
Reviewed-by: Daniel M. Crowell <dcrowell@us.ibm.com>
Diffstat (limited to 'src/build')
-rw-r--r-- | src/build/linker/linker.C | 39 | ||||
-rw-r--r-- | src/build/mkrules/cflags.env.mk | 14 |
2 files changed, 38 insertions, 15 deletions
diff --git a/src/build/linker/linker.C b/src/build/linker/linker.C index 9e4751e41..a9a9d0f5e 100644 --- a/src/build/linker/linker.C +++ b/src/build/linker/linker.C @@ -283,6 +283,36 @@ inline void advance_to_page_align(FILE * i_f) } } +/** + * @brief Throw error if std::fread was performed incorrectly. + * @param[i] i_buffer: pointer to the first object in the array to be read + * @param[i] i_size: size of each object in i_buffer array, in bytes + * @param[i] i_count: number of the objects in i_buffer array to be read + * @param[i] i_stream: input-file pointer + */ +inline void fread_wrapper(void* i_buffer, const size_t i_size, + const size_t i_count, FILE* i_stream) +{ + + size_t n_values_read = fread(i_buffer,i_size,i_count,i_stream); + + if (i_count != n_values_read) + { + if (feof(i_stream)) + { + throw "End of file reached, file not read fully."; + } + else if (ferror(i_stream)) + { + throw "Error occurred while reading file."; + } + else + { + throw "Unknown read error."; + } + } +} + // // Global variables // @@ -669,7 +699,7 @@ bool Object::write_object() long int file_size = ftell(file); uint8_t * buffer = new uint8_t[file_size]; fseek(file,0,SEEK_SET); - fread(buffer,file_size,1,file); + fread_wrapper(buffer,file_size,1,file); fwrite(buffer,file_size,1,iv_output); delete [] buffer; fclose(file); @@ -895,7 +925,7 @@ bool Object::perform_local_relocations() bool is_weak = false; fseek(iv_output, offset + i->address, SEEK_SET); - fread(data, sizeof(uint64_t), 1, iv_output); + fread_wrapper(data, sizeof(uint64_t), 1, iv_output); if (weak_symbols.find(i->name) != weak_symbols.end()) { @@ -1024,7 +1054,8 @@ bool Object::perform_global_relocations() } fseek(j->iv_output, symbol_addr, SEEK_SET); - fread(data, sizeof(uint64_t), 3, j->iv_output); + fread_wrapper(data, sizeof(uint64_t), 3, + j->iv_output); fseek(iv_output, offset + i->address, SEEK_SET); fwrite(data, sizeof(uint64_t), 3, iv_output); @@ -1172,7 +1203,7 @@ void ModuleTable::write_table(vector<Object> & i_objects) cout << "Updating base module table..." << endl; fseek(iv_output, module_table_offset, SEEK_SET); char mx_mod_ch = 0; - fread(&mx_mod_ch,sizeof(char),1,iv_output); + fread_wrapper(&mx_mod_ch,sizeof(char),1,iv_output); max_modules = (uint64_t)mx_mod_ch; // VFS_MODULE_MAX; ++i; } diff --git a/src/build/mkrules/cflags.env.mk b/src/build/mkrules/cflags.env.mk index 732e6559e..04ff6fedd 100644 --- a/src/build/mkrules/cflags.env.mk +++ b/src/build/mkrules/cflags.env.mk @@ -38,22 +38,14 @@ CFLAGS += -DNO_INITIALIZER_LIST CFLAGS += -D__FAPI endif -try = $(shell set -e; if ($(1)) >/dev/null 2>&1; \ - then echo "$(2)"; \ - else echo "$(3)"; fi ) - -try-cflag = $(call try,$(1) $(2) -x c -c /dev/null -o /dev/null,$(2)) -test_cflag = $(call try,$(1) $(2) -x c -c /dev/null -o /dev/null,1,0) COMMONFLAGS += $(OPT_LEVEL) -nostdlib CFLAGS += $(COMMONFLAGS) -mcpu=power7 -nostdinc -g -mno-vsx -mno-altivec\ - -Wall -mtraceback=no -pipe -mabi=elfv1 \ - $(call try-cflag,$(CC),-Wno-error=sizeof-array-argument) \ - $(call try-cflag,$(CC),-Wno-error=unused-function) \ + -Werror -Wall -mtraceback=no -pipe -mabi=elfv1 \ -ffunction-sections -fdata-sections -ffreestanding -mbig-endian ASMFLAGS += $(COMMONFLAGS) -mcpu=power7 -mbig-endian -ffreestanding -mabi=elfv1 -CXXFLAGS += $(CFLAGS) -nostdinc++ -fno-rtti -fno-exceptions -Wall \ - -fuse-cxa-atexit -std=gnu++14 -fpermissive +CXXFLAGS += $(CFLAGS) -nostdinc++ -fno-rtti -fno-exceptions -Werror -Wall \ + -fuse-cxa-atexit -std=gnu++14 LDFLAGS += --nostdlib --sort-common -EB $(COMMONFLAGS) INCFLAGS = $(addprefix -I, $(INCDIR) ) |