Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

P8 build fixes for modern GCC #193

Open
wants to merge 15 commits into
base: master-p8
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 35 additions & 4 deletions src/build/linker/linker.C
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,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
//
Expand Down Expand Up @@ -597,7 +627,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);
Expand Down Expand Up @@ -795,7 +825,7 @@ bool Object::perform_local_relocations()
char data[sizeof(uint64_t)];

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);

address = bfd_getb64(data);
if ((address != i->addend) && (address != 0))
Expand Down Expand Up @@ -885,7 +915,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);
Expand Down Expand Up @@ -996,7 +1027,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;
}
Expand Down
8 changes: 5 additions & 3 deletions src/build/mkrules/cflags.env.mk
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ CFLAGS += -D__HOSTBOOT_MODULE=$(MODULE)
endif

COMMONFLAGS += $(OPT_LEVEL) -nostdlib
# TODO RTC: 123994 - ELFv2 ABI support (-mabi=elfv1)
CFLAGS += $(COMMONFLAGS) -mcpu=power7 -nostdinc -g -mno-vsx -mno-altivec\
-Wall -Werror -mtraceback=no -pipe \
-ffunction-sections -fdata-sections -ffreestanding -mbig-endian
ASMFLAGS += $(COMMONFLAGS) -mcpu=power7 -mbig-endian
-ffunction-sections -fdata-sections -ffreestanding -mbig-endian \
-mabi=elfv1
ASMFLAGS += $(COMMONFLAGS) -mcpu=power7 -mbig-endian -mabi=elfv1
CXXFLAGS += $(CFLAGS) -nostdinc++ -fno-rtti -fno-exceptions -Wall \
-fuse-cxa-atexit
-fuse-cxa-atexit -std=gnu++03
LDFLAGS += --nostdlib --sort-common -EB $(COMMONFLAGS)

INCFLAGS = $(addprefix -I, $(INCDIR) )
Expand Down
16 changes: 6 additions & 10 deletions src/build/trace/tracehash.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/* */
/* OpenPOWER HostBoot Project */
/* */
/* Contributors Listed Below - COPYRIGHT 2013,2015 */
/* Contributors Listed Below - COPYRIGHT 2013,2017 */
/* [+] International Business Machines Corp. */
/* */
/* */
Expand Down Expand Up @@ -471,14 +471,7 @@ void create_sections(bfd* inFile, asection* s, void* param)
// for this section to point to the group
// symbol
// Binutils 2.24 BFD requires an offset of 176
// Binutils 2.22 BFD requires an offset of 168
// So we're just going to key off a define that's only in 2.24
// TODO RTC 123492
#ifdef bfd_find_nearest_line_discriminator
uint32_t offset = 176;
#else
uint32_t offset = 168;
#endif
void *ptr_sym_offset = s->used_by_bfd + offset;
asymbol **tsym = (asymbol **)ptr_sym_offset;
*tsym = gsym;
Expand Down Expand Up @@ -672,7 +665,10 @@ char* create_format_string(const char* string)
size_t r_pos = 0; // Current position in result string.

// Iterate through source string looking for format tags.
for(size_t pos = 0; pos < length; pos++)
// length - 2 was used because "length" already includes the 0 terminal byte
// and we want to make sure we have at least one char beyond the "%"
// that way we have two which should deal with most cases
for(size_t pos = 0; pos < (length-2); pos++)
{
// Skip if not %.
if (string[pos] != '%') continue;
Expand Down Expand Up @@ -889,7 +885,7 @@ void parse_traceinfo(bfd* inFile, asection* s)
static const char filesep[] = ": ";

size_t len_begin = replace_pos - (char*)&contents[pos];
size_t len_end = strlen(&contents[pos]) -
size_t len_end = strlen(&contents[pos + len_begin]) -
strlen(TRACEPP_REPLACE_WITH_FILENAME);
size_t length = len_begin + strlen(filename) + len_end +
strlen(filesep) + 1;
Expand Down
2 changes: 1 addition & 1 deletion src/include/kernel/cpumgr.H
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class CpuManager
*/
static uint64_t cv_cpuSeq;

static bool cv_forcedMemPeriodic; //!< force free / coalesce.
static uint8_t cv_forcedMemPeriodic; //!< force free / coalesce.

// If a shutdown of all CPUs is requested
static bool cv_shutdown_requested;
Expand Down
18 changes: 13 additions & 5 deletions src/include/usr/devicefw/driverif.H
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ namespace DeviceFW
TargType i_targetType,
deviceOp_t i_regRoute)
{
return InvalidParameterType(); // Cause a compile fail if not one of
InvalidParameterType(); // Cause a compile fail if not one of
// the explicit template specializations.
}

Expand Down Expand Up @@ -324,8 +324,12 @@ namespace DeviceFW
void* io_buffer, size_t& io_buflen,
AccType i_accessType, ...)
{
return InvalidParameterType(); // Cause a compile fail if not one of
// the explicit template specializations.
// Cause a compile fail if not one of
// the explicit template specializations.
static_assert(sizeof(AccType) != sizeof(AccType), "Must use"
" an explicitly supported template specialization");
errlHndl_t errl = nullptr;
return errl;
}

/**
Expand All @@ -349,8 +353,12 @@ namespace DeviceFW
void* io_buffer, size_t& io_buflen,
AccType i_accessType, va_list i_args)
{
return InvalidParameterType(); // Cause a compile fail if not one of
// the explicit template specializations.
// Cause a compile fail if not one of
// the explicit template specializations.
static_assert(sizeof(AccType) != sizeof(AccType), "Must use"
" an explicitly supported template specialization");
errlHndl_t errl = nullptr;
return errl;
}

// --- Below are template specializations to aid in type-safety. ---
Expand Down
7 changes: 7 additions & 0 deletions src/include/usr/hwpf/hwp/mvpd_accessors/getMBvpdAttr.H
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,13 @@ namespace getAttrData
uint8_t iv_systemType;
uint8_t iv_systemType_ext;
uint8_t iv_dataVersion;
public:
MBvpdVMKeyword() : iv_version(0),iv_systemType(0),
iv_systemType_ext(0),iv_dataVersion(0) {};
operator uint32_t() const {
return iv_version << 24 | iv_systemType << 16 |
iv_systemType_ext << 8 | iv_dataVersion;
}
};
// Attribute definition
struct MBvpdAttrDef
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#define _HWP_GETMBVPDMEMDATAVERSION_

#include <fapi.H>
#define VM_KEYWORD_DEFAULT_VALUE 0x00000000

// function pointer typedef definition for HWP call support
typedef fapi::ReturnCode (*getMBvpdMemoryDataVersion_FP_t)
Expand Down
25 changes: 13 additions & 12 deletions src/include/usr/targeting/common/target.H
Original file line number Diff line number Diff line change
Expand Up @@ -611,8 +611,8 @@ bool Target::tryGetAttr(typename AttributeTraits<A>::Type& o_attrValue) const
template<const ATTRIBUTE_ID A>
bool Target::trySetAttr(typename AttributeTraits<A>::Type const& i_attrValue)
{
if(AttributeTraits<A>::writeable) { }
if(AttributeTraits<A>::notHbMutex) { }
if(AttributeTraits<A>::writeable == AttributeTraits<A>::writeable) { }
if(AttributeTraits<A>::notHbMutex == AttributeTraits<A>::notHbMutex) { }
return _trySetAttr(A,sizeof(i_attrValue),&i_attrValue);
}

Expand Down Expand Up @@ -641,28 +641,28 @@ void Target::setAttr(typename AttributeTraits<A>::Type const& i_attrValue)
template<const ATTRIBUTE_ID A>
mutex_t* Target::getHbMutexAttr() const
{
if(AttributeTraits<A>::hbMutex) { }
if(AttributeTraits<A>::readable) { }
if(AttributeTraits<A>::writeable) { }
if(AttributeTraits<A>::hbMutex == AttributeTraits<A>::hbMutex) { }
if(AttributeTraits<A>::readable == AttributeTraits<A>::readable) { }
if(AttributeTraits<A>::writeable == AttributeTraits<A>::writeable) { }
return _getHbMutexAttr(A);
}

template<const ATTRIBUTE_ID A>
util::Mutex* Target::getFspMutexAttr() const
{
if(AttributeTraits<A>::fspMutex) { }
if(AttributeTraits<A>::readable) { }
if(AttributeTraits<A>::writeable) { }
if(AttributeTraits<A>::fspMutex == AttributeTraits<A>::fspMutex) { }
if(AttributeTraits<A>::readable == AttributeTraits<A>::readable) { }
if(AttributeTraits<A>::writeable == AttributeTraits<A>::writeable) { }
return _getFspMutexAttr(A);
}

template<const ATTRIBUTE_ID A>
bool Target::tryGetHbMutexAttr(
mutex_t*& o_pMutex) const
{
if(AttributeTraits<A>::hbMutex) { }
if(AttributeTraits<A>::readable) { }
if(AttributeTraits<A>::writeable) { }
if(AttributeTraits<A>::hbMutex == AttributeTraits<A>::hbMutex) { }
if(AttributeTraits<A>::readable == AttributeTraits<A>::readable) { }
if(AttributeTraits<A>::writeable == AttributeTraits<A>::writeable) { }
return _tryGetHbMutexAttr(A,o_pMutex);
}

Expand All @@ -672,7 +672,8 @@ const char* Target::getAttrAsString() const
// Note: the compiler optimizes the following check (which fails
// at compile time if the attribute does not have a string
// conversion) away
if(AttributeTraits<A>::hasStringConversion) { }
if(AttributeTraits<A>::hasStringConversion ==
AttributeTraits<A>::hasStringConversion) { }
typename AttributeTraits<A>::Type l_attrValue;
bool l_read = tryGetAttr<A>(l_attrValue);
if (unlikely(!l_read))
Expand Down
10 changes: 6 additions & 4 deletions src/include/util/locked/list.H
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
/* */
/* OpenPOWER HostBoot Project */
/* */
/* COPYRIGHT International Business Machines Corp. 2010,2014 */
/* Contributors Listed Below - COPYRIGHT 2010,2019 */
/* [+] International Business Machines Corp. */
/* */
/* */
/* Licensed under the Apache License, Version 2.0 (the "License"); */
/* you may not use this file except in compliance with the License. */
Expand Down Expand Up @@ -42,9 +44,9 @@ namespace Util
void insert(_T*);

void erase(_T* node);
void erase(_K& key);
_T* erase(_K& key);

_T* find(_K& key) const;
_T* find(_K& key) const;

bool empty();
_T* begin();
Expand Down Expand Up @@ -156,7 +158,7 @@ namespace Util
}

template <typename _T, typename _K, bool locked, typename _S>
void List<_T,_K,locked,_S>::erase(_K& key)
_T* List<_T,_K,locked,_S>::erase(_K& key)
{
__lock();

Expand Down
6 changes: 3 additions & 3 deletions src/kernel/cpumgr.C
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ cpu_t** CpuManager::cv_cpus[KERNEL_MAX_SUPPORTED_NODES];
bool CpuManager::cv_shutdown_requested = false;
uint64_t CpuManager::cv_shutdown_status = 0;
size_t CpuManager::cv_cpuSeq = 0;
bool CpuManager::cv_forcedMemPeriodic = false;
uint8_t CpuManager::cv_forcedMemPeriodic = 0;
InteractiveDebug CpuManager::cv_interactive_debug;

CpuManager::CpuManager() : iv_lastStartTimebase(0)
Expand Down Expand Up @@ -361,7 +361,7 @@ void CpuManager::executePeriodics(cpu_t * i_cpu)
}

bool forceMemoryPeriodic = __sync_fetch_and_and(&cv_forcedMemPeriodic,
false);
0);

++(i_cpu->periodic_count);
if((0 == (i_cpu->periodic_count % CPU_PERIODIC_CHECK_MEMORY)) ||
Expand Down Expand Up @@ -461,7 +461,7 @@ size_t CpuManager::getThreadCount()

void CpuManager::forceMemoryPeriodic()
{
cv_forcedMemPeriodic = true;
cv_forcedMemPeriodic = 1;
}


Expand Down
10 changes: 6 additions & 4 deletions src/kernel/shutdown.S
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
#
# OpenPOWER HostBoot Project
#
# COPYRIGHT International Business Machines Corp. 2012,2014
# Contributors Listed Below - COPYRIGHT 2012,2017
# [+] International Business Machines Corp.
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -92,7 +94,7 @@ kernel_shutdown_ea0_1_mode:
;// as it was the one that updated the cpu_count & lowest_pir
;// barrier - 1 wait for all nodes to report
mfspr r10, PIR
cmp cr0, r10, r7
cmpw cr0, r10, r7
bne+ 2f ;// inside KERNEL_BARRIER below

;// Perform barrier - 1
Expand Down Expand Up @@ -131,7 +133,7 @@ kernel_shutdown_ea0_1_mode:
addi r8, r8, 8
;// Check for PIR == r7.
mfspr r10, PIR
cmp cr0, r10, r7
cmpw cr0, r10, r7
beq 3f
;// Increment thread count.
1:
Expand Down Expand Up @@ -164,7 +166,7 @@ kernel_shutdown_ea0_1_mode:
1:
or 1,1,1
ld r11, 0(r8)
cmp cr0, r3, r11
cmpw cr0, r3, r11
bne+ 1b
isync
;// All other threads have left, so wait a little bit...
Expand Down
9 changes: 7 additions & 2 deletions src/lib/utilmisc.C
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,19 @@ namespace Util
{

bool isSimics() __attribute__((alias("__isSimicsRunning")));
extern "C" void __isSimicsRunning() NEVER_INLINE;
extern "C" bool __isSimicsRunning() NEVER_INLINE;

void __isSimicsRunning()
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wreturn-type"

bool __isSimicsRunning()
{
asm volatile("li 3, 0");
MAGIC_INSTRUCTION(MAGIC_SIMICS_CHECK);
}

#pragma GCC diagnostic pop

bool isSimicsRunning()
{
static bool simics = isSimics();
Expand Down
2 changes: 1 addition & 1 deletion src/usr/console/uart.C
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ namespace CONSOLE
// Wait for transmit FIFO to have space.
{
const uint64_t DELAY_NS = 100;
const uint64_t DELAY_LOOPS = 10000;
const uint64_t DELAY_LOOPS = 100000000;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add an explanation for this in the commit message please?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've got no idea why this was done. The commit message from 2014 was as follows:

Changes for Habanero bringup, uart delay and centaur/vddr

Note that every openpower machine has carried this change. It was placed in the op-build tree instead of committed to the hostboot repository for unknown reasons.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no explanation beyond wishful thinking on why it remained as a patch for so long.


uint8_t data = 0;
uint64_t loops = 0;
Expand Down
Loading