hercules-390 / hyperion

Hercules 390
Other
246 stars 69 forks source link

Not all compilers/OSes support -march=native. NetBSD 7.0.1 & gcc 4.8.4 reject it. #244

Open Rhialto opened 6 years ago

Rhialto commented 6 years ago

When compiling on NetBSD 7 (after my previous fix), building fails with

make  all-recursive
Making all in decNumber
  CC       decContext.lo
/mnt/vol1/rhialto/cvs/other/hercules/hyperion/decNumber/decContext.c:1:0: error: bad value (native) for -march= switch
 /* ------------------------------------------------------------------ */
 ^
*** Error code 1

Stop.

Apparently -march=native is not supported by this version of gcc. It should be tested by configure, not just assumed by version number. It varies by cpu architecture and OS, whether this works. Just commenting out the section that sets the value doesn't work; then -march= is supplied and that fails too. No patch yet.

ivan-w commented 6 years ago

Acknowledged... It is an issue !

Workaround :

./configure --enable-optimization='-Ox -march=xxx' ( x set to whatever you want or simply omit "-march=" which will then use the lowest common denominator)

--Ivan

Rhialto commented 6 years ago

Ah thanks, with that I get a whole lot further. I'll experiment later if it works or if more patches are needed :-)

srorso commented 6 years ago

Hi,

I am re-opening this issue so a correction and any discussion about -march=native can be separated from the IPV6 header test correction, documented in #243, that you have developed for compilations under NetBSD.

Best Regards, Steve Orso

srorso commented 6 years ago

From #244, herc4mac wrote on 26 Jan 2018

I will see if I can develop a robust correction for CMake.

cmake provides already the solution

CheckCCompilerFlag

no need to look at the compiler name , just check if the flag is supported

the same approach can be used in configure.ac

http://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html http://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html

Hi Enrico,

Thanks! That will help me here and in a couple of other places...

Best Regards, Steve Orso

ghost commented 6 years ago

the function ( I prefer using functions - no surprised from clashing variable names )

[[ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

checkCompilerFlags.cmake
Copyright Enrico Sorichetti 2017 - 2017
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)

]]

[[ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

]]

if( CMAKE_VERSION VERSION_GREATER_EQUAL "3.10" ) include_guard( GLOBAL ) endif()

[[ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

]]

include( CMakePushCheckState ) include( CheckCCompilerFlag )

function( check_compiler_flags ) set( args "${ARGV}") list( REMOVE_DUPLICATES args ) cmake_push_check_state() set( CMAKE_REQUIREDFLAGS "-Wall -Werror" ) foreach( argv ${args} ) string( REGEX REPLACE "[^a-zA-Z0-9]" "_" flag "have_flag${argv}") string( TOUPPER "${flag}" flag ) if( COMMAND build_cmakedefs ) build_cmakedefs( "flags.h.in" "${flag}" ) endif() check_c_compiler_flag( ${argv} "${flag}" ) endforeach() cmake_pop_check_state() endfunction()

how I use it

[[ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

the optimization flags

]]

include( checkCompilerFlags ) check_compiler_flags( "-fno-omit-frame-pointer" "-fomit-frame-pointer" "-mtune=native" )

srorso commented 6 years ago

Hi Rhialto,

After more than a few trials getting a NetBSD running in a VirtualBox, detailed in #243, I was able to build a system that will be a test bed for this issue's correction. I also saw many redefinition of type warnings when building SoftFloat-3a for Hercules. Did you see these as well?

I never got NetBSD 7.1.1 running; that version uses gcc 4.8.5 as do CentOS 7 and Leap 42.x. It would have been interesting to see if -march=native would work on NetBSD 7.1.1. In any event, it does not work on 4.8.4/NetBSD, and I do not have other systems available with gcc 4.8.4. I recently archived my Ubuntu 14 system, which did use gcc 4.8.4 and did accept -march=native, so I may re-build that system.

Now I can get a fix put together.

Many thanks for your patience.

Best Regards, Steve Orso

srorso commented 6 years ago

Hi Rhialto,

This is not a problem. I have wanted another BSD in my testing mix, which has a fair number of Linux variants, FreeBSD, Solaris, and Windows 10. OpenBSD is out of the question because it does not support thread-local storage, something that SoftFloat-3 requires. Because NetBSD reveals an "interesting issue," it is worth the effort.

I re-built my Ubuntu 14.04, which also uses gcc 4.8.4, the version included in NetBSD 7.0.1. Hercules can be built with -march=native using CMake. Haven't tried autotools but I do not expect a different result.

I have to assume (at the usual risk) that NedBSD disallows -march=native. I took a brief dive into the NetBSD sources to see if I could find out where and then why, but decided quickly I did not want to be a gcc developer nor a distro builder, and I came back up for air.

The result difference between NetBSD/gcc 4.8.4 and Ubuntu 14.04 LTS/gcc 4.8.4 confirms the value of Enrico's suggestion to disregard compiler level and just test proposed C flags by using them in a trial compilation.

This diagnostic process has uncovered a few other errors I made coding the gcc optimization stuff in CMake. These will need to be addressed; the result of those errors is the inclusion of -O3 in CMake builds.

Some thinking is also needed around how to handle the -DOPTIMIZE option versus CMake's ability to generate multiple build configurations (Release, Debug, etc) for selected environments (Apple Xcode: GUI and Command Line Tools, Visual Studio: GUI and Build Tools). While gcc is generally only used in single-configuration environments, there is no requirement for this, and there is the need to avoid lots of "works this way in XCode/MSVC, that way in make/ninja/Eclipse/KDevelop/Kate Projects."

One possibility is deprecating the -DOPTIMIZE="option string" option; YES and NO would still be valid. YES means automatic optimization for Release builds (the default for single-configuration build tools like make), NO means no optimization for Release builds. Optimization flags would not be added to Debug builds. If one wishes specific optimization flags, they would be specified using the existing CMake option -DCMAKE_C_FLAGS_<config-type>; this would allow builder-specified optimizations in a Debug build.

Now back to the issue you first encountered. An alternative to your commenting out line 196 in Herc31_COptsGNU.cmake, would you consider changing line 196 to:

        set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=${CMAKE_SYSTEM_PROCESSOR}" )

This is the planned outcome if additional code in that script determines that -march=native does not work in the compiler being used.

In the meantime, thanks for your patience while this gets worked out.

Best Regards, Steve Orso

Rhialto commented 6 years ago

Hi Steve,

I tried that, and then it tries -march=x86_64. Weirdly enough that is also not accepted. I thought that maybe amd64 might be the value it wants, but no such luck. It turns out it wants -march=x86-64 with a hyphen instead of an underscore...

srorso commented 6 years ago

Hi Rhialto,

I borrowed some SCUBA gear and dove back in to NetBSD. Found nothing interesting, and having plenty of air, I delved in to gcc 4.8.4 and found some interesting reading at gcc/config/driver-i386.c.

driver-i386.c includes a function that deals with both -mtune=native and -march=native. The function probes the processor hardware and replaces -march/-mtune=native with a specific gcc CPU type and adds a number of -m options that are supported by the host processor.

This led to experimentation. Using gcc 4.8.4, compilation of a trivial c program with -march=native failed (duh!) and with -march=x86-64 -mtune=native worked. Interesting. CentOS7 (gcc 4.8.4) was used to compile the same trivial program. Both -march=native and -march=x86-64 -mtune=native worked fine. That result suggested trials with the newer versions of gcc available in the NetBSD 7.0.1 repository. Versions 4.8.5 and newer on NetBSD are good with -march=native.

For what it's worth, there are no differences between the 4.8.4 and 4.8.5 versions of driver-i386.c. The issue is elsewhere, and I believe finding it would require construction of an underwater habitat.

At this point, I surfaced and returned the SCUBA gear.

While this investigation does not provide a solution because I prefer not to offer "install a newer compiler" as an appropriate closing for a Hercules issue, it does suggest a) an alternative to -march=native on an affected system and b) that the population of affected systems is very small. NetBSD 7.1.1, if it could be installed, comes with gcc 4.8.5 and is less likely to have this issue.

Best Regards, Steve Orso