GNU make 3.82 run time error on Ubuntu-20.04: Segmentation fault (core dumped) - gnu-make

I downloaded gnu-make-3.82 from GNU and make & install it on a specific directory (e.g. dir) on my Ubuntu-20.04 machine.
Then I run
$file dir/make
It returns:
ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=ef2934bdbc32938713fd4cb1c9a733e8b6785af0, for GNU/Linux 3.2.0, with debug_info, not stripped
When I run
$dir/make --version
It returns:
GNU Make 3.82
Built for x86_64-unknown-linux-gnu
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
When I run it with even the simplest Makefile, it generates the error:
Segmentation fault (core dumped)
Why? What additional work I need to do to make it work well?

According to tips from #steeldriver, I made the following changes to dir.c.
diff --git a/dir.c b/dir.c
index adbb8a9..c343e4c 100644
--- a/dir.c
+++ b/dir.c
## -1299,15 +1299,40 ## local_stat (const char *path, struct stat *buf)
}
#endif
+/* Similarly for lstat. */
+#if !defined(lstat) && !defined(WINDOWS32) || defined(VMS)
+# ifndef VMS
+# ifndef HAVE_SYS_STAT_H
+int lstat (const char *path, struct stat *sbuf);
+# endif
+# else
+ /* We are done with the fake lstat. Go back to the real lstat */
+# ifdef lstat
+# undef lstat
+# endif
+# endif
+# define local_lstat lstat
+#elif defined(WINDOWS32)
+/* Windows doesn't support lstat(). */
+# define local_lstat local_stat
+#else
+static int
+local_lstat (const char *path, struct stat *buf)
+{
+ int e;
+ EINTRLOOP (e, lstat (path, buf));
+ return e;
+}
+#endif
+
void
dir_setup_glob (glob_t *gl)
{
gl->gl_opendir = open_dirstream;
gl->gl_readdir = read_dirstream;
gl->gl_closedir = free;
+ gl->gl_lstat = local_lstat;
gl->gl_stat = local_stat;
- /* We don't bother setting gl_lstat, since glob never calls it.
- The slot is only there for compatibility with 4.4 BSD. */
}
Then remake the make and run it. It works fine without any warnings or erros.

Related

how to make loadable kernel module on solaris? no linux

1. how to create loadable kernel module on solaris 11?
simple loadable kernel module (hello world).
I searched, but only showed how to create a Linux kernel module.
in linux, header linux/kernel.h, but not included header on solaris
2. how to compile loadable kernel module on solaris 11?
gcc -D_KERNEL -m64 -c cpluscplus.cpp
Is it appropriate to compile as above?
64bit, x86
Here's the minimal hello world kernel module I can come up with:
#include <sys/modctl.h>
#include <sys/cmn_err.h>
/*
* Module linkage information for the kernel.
*/
static struct modlmisc modlmisc = {
&mod_miscops, "test module"
};
static struct modlinkage modlinkage = {
MODREV_1, (void *)&modlmisc, NULL
};
int
_init(void)
{
return (mod_install(&modlinkage));
}
int
_fini(void)
{
return (mod_remove(&modlinkage));
}
int
_info(struct modinfo *modinfop)
{
cmn_err(CE_NOTE, "hello kernel");
return (mod_info(&modlinkage, modinfop));
}
Compiling this as 64-bit binary with Oracle Developer Studio 12.6 and the Solaris linker like so:
cc -D_KERNEL -I include -m64 -c foomod.c
ld -64 -z type=kmod -znodefs -o foomod foomod.o
For GCC you will likely need a distinct set of options.
Then load it with:
modload ./foomod
This will complain about signature verification. This is innocuous unless you are running the system with Verified Boot enabled.
Check that module is loaded:
# modinfo -i foomod
ID LOADADDR SIZE INFO REV NAMEDESC
312 fffffffff7a8ddc0 268 -- 1 foomod (test module)
# dmesg | tail -1
Mar 16 12:22:57 ST091 foomod: [ID 548715 kern.notice] NOTICE: hello kernel
This works on Solaris 11.4 SRU 33 running on x86 machine (VirtualBox instance in fact).

OpenJDK - undefined symbol _ZN23G1SATBCardTableModRefBS24write_ref_array_pre_work

After successfully building OpenJDK on linux, I'm facing a runtime error on executing java
This is the error -
rkbalgi#osboxes ~/jvm_work/openjdk8 $ ./build/linux-x86_64-normal-server-release/jdk/bin/java -version
Error: dl failure on line 864
Error: failed /home/rkbalgi/jvm_work/openjdk8/build/linux-x86_64-normal-server-release/jdk/lib/amd64/server/libjvm.so, because /home/rkbalgi/jvm_work/openjdk8/build/linux-x86_64-normal-server-release/jdk/lib/amd64/server/libjvm.so: undefined symbol: _ZN23G1SATBCardTableModRefBS24write_ref_array_pre_workIP7oopDescEEvPT_i
The bootstrap JDK used during build is -
rkbalgi#osboxes ~/jvm_work/openjdk8 $ /usr/lib/jvm/java-7-openjdk-amd64/bin/java -version
java version "1.7.0_95"
OpenJDK Runtime Environment (IcedTea 2.6.4) (7u95-2.6.4-3)
OpenJDK 64-Bit Server VM (build 24.95-b01, mixed mode)
OS Info -
rkbalgi#osboxes ~/jvm_work/openjdk8 $ uname -a
Linux osboxes 4.4.0-53-generic #74-Ubuntu SMP Fri Dec 2 15:59:10 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
Any pointers to what could be the issue?
This error can be fixed by moving template method write_ref_array_pre_work to header g1SATBCardTableModRefBS.hpp as described here (sorry, link in Chinese, but this is the only solution that I found)
In $hotspot/src/share/vm/gc_implementation/g1 ,there is two files.
g1SATBCardTableModRefBS.cpp
g1SATBCardTableModRefBS.hpp
you should move template method write_ref_array_pre_work from g1SATBCardTableModRefBS.cpp to g1SATBCardTableModRefBS.hpp
I added it to g1SATBCardTableModRefBS.hpp just like the blow.
Notice:You should change G1SATBCardTableModRefBS:: (T* dst, int count) to (T* dst, int count),or you will get extra qualification error in C++
template <class T> void write_ref_array_pre_work(T* dst, int count) {
if (!JavaThread::satb_mark_queue_set().is_active()) return;
T* elem_ptr = dst;
for (int i = 0; i < count; i++, elem_ptr++) {
T heap_oop = oopDesc::load_heap_oop(elem_ptr);
if (!oopDesc::is_null(heap_oop)) {
enqueue(oopDesc::decode_heap_oop_not_null(heap_oop));
}
}
}
It worked for me when I'm using make version 3.8.1.

QT powershell error windows-build-qt-static.ps1

After 6-7 attempts to compile QT static version i used this article Building_a_static_Qt_for_Windows_using_MinGW
and again errors:
I have installed QT 5.7.
I downloaded
windows-build-qt-static.ps1 then changing the necessary lines
[CmdletBinding()]
param(
$QtSrcUrl = "https://download.qt.io/snapshots/qt/5.8/5.8.0/latest_src/qt-everywhere-opensource-src-5.8.0.7z",
$QtStaticDir = "C:\Qt\Static",
$QtVersion = "5.7",
$MingwDir = "C:\Qt\Tools\mingw530_32\bin\gcc.exe",
[switch]$NoPause = $false
)
and the error is
Windows PowerShell
Copyright (C) 2012 Microsoft Corporation. All rights reserved.
PS C:\Users\Admin> C:\Qt\windows-build-qt-static.ps1
Building static Qt version 5.7
Using MinGW from C:\Qt\Tools\mingw530_32\bin\gcc.exe
Downloading https://download.qt.io/snapshots/qt/5.8/5.8.0/latest_src/qt-everywhere-opensource-src-5.8.0.7z ...
Expanding C:\Qt\Static\src\qt-everywhere-opensource-src-5.8.0.7z ...
7-Zip [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
Scanning the drive for archives:
1 file, 353390329 bytes (338 MiB)
--
Path = C:\Qt\Static\src\qt-everywhere-opensource-src-5.8.0.7z
Type = 7z
Physical Size = 353390329
Headers Size = 1959904
Method = LZMA2:24
Solid = +
Blocks = 1
Everything is Ok
Folders: 17053
Files: 155016
Size: 1670093035
Compressed: 353390329
Patching C:\Qt\Static\src\qt-everywhere-opensource-src-5.8.0\qtbase\mkspecs\win32-g++\qmake.conf ...
+ cd qtbase
+ C:\Qt\Static\src\qt-everywhere-opensource-src-5.8.0\qtbase\configure.bat -top-level -static -debug-and-release -platfo
rm win32-g++ -prefix C:\Qt\Static\5.7 -qt-zlib -qt-pcre -qt-libpng -qt-libjpeg -qt-freetype -opengl desktop -qt-
sql-sqlite -no-openssl -opensource -confirm-license -make libs -nomake tools -nomake examples -nomake te
sts
Please wait while bootstrapping configure ...
Perl not found in PATH. Aborting.
mingw32-make : The term 'mingw32-make' is not recognized as the name of a cmdlet, function, script file, or operable pr
ogram. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Qt\windows-build-qt-static.ps1:170 char:5
+ mingw32-make -k -j4
+ ~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (mingw32-make:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
mingw32-make : The term 'mingw32-make' is not recognized as the name of a cmdlet, function, script file, or operable pr
ogram. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Qt\windows-build-qt-static.ps1:171 char:5
+ mingw32-make -k install
+ ~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (mingw32-make:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Out-File : Could not find a part of the path 'C:\Qt\Static\5.7\mkspecs\win32-g++\qmake.conf'.
At C:\Qt\windows-build-qt-static.ps1:178 char:6
+ "# | Out-File -Append $File -Encoding Ascii
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OpenError: (:) [Out-File], DirectoryNotFoundException
+ FullyQualifiedErrorId : FileOpenFailure,Microsoft.PowerShell.Commands.OutFileCommand
Please wait while bootstrapping configure ...
Perl not found in PATH. Aborting.
mingw32-make : The term 'mingw32-make' is not r .....
Out-File : Could not find a part of the path 'C:\Qt\Static\5.7\mkspecs\win32-g++\qmake.conf'.
At C:\Qt\windows-build-qt-static.ps1:178 char:6
+ "# | Out-File -Append $File -Encoding Ascii
This windows-build-qt-static.ps1 script worked for me a year ago.
Note at line 117, I just removed one * from path C:\Qt\Tools\mingw*\bin\gcc.exe between Qt\ and Tools
#-----------------------------------------------------------------------------
#
# Copyright (c) 2013-2015, Thierry Lelegard
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
# THE POSSIBILITY OF SUCH DAMAGE.
#
#-----------------------------------------------------------------------------
<#
.SYNOPSIS
Build a static version of Qt for Windows.
.DESCRIPTION
This scripts downloads Qt source code, compiles and installs a static version
of Qt. It assumes that a prebuilt Qt / MinGW environment is already installed,
typically in C:\Qt. This prebuilt environment uses shared libraries. It is
supposed to remain the main development environment for Qt. This script adds
a static version of the Qt libraries in order to allow the construction of
standalone and self-sufficient executable.
This script is typically run from the Windows Explorer.
Requirements:
- Windows PowerShell 3.0 or higher.
- 7-zip.
.PARAMETER QtSrcUrl
URL of the Qt source file archive.
By default, use the latest identified version.
.PARAMETER QtStaticDir
Root directory where the static versions of Qt are installed.
By default, use C:\Qt\Static.
.PARAMETER QtVersion
The Qt version. By default, this script tries to extract the version number
from the Qt source file name.
.PARAMETER MingwDir
Root directory of the MinGW prebuilt environment. By default, use the version
which was installed by the prebuilt Qt environment.
.PARAMETER NoPause
Do not wait for the user to press <enter> at end of execution. By default,
execute a "pause" instruction at the end of execution, which is useful
when the script was run from Windows Explorer.
#>
[CmdletBinding()]
param(
$QtSrcUrl = "http://download.qt.io/official_releases/qt/5.5/5.5.1/single/qt-everywhere-opensource-src-5.5.1.7z",
$QtStaticDir = "C:\Qt\Static",
$QtVersion = "",
$MingwDir = "",
[switch]$NoPause = $false
)
# PowerShell execution policy.
Set-StrictMode -Version 3
#-----------------------------------------------------------------------------
# Main code
#-----------------------------------------------------------------------------
function Main
{
# Check that 7zip is installed. We use it to expand the downloaded archive.
[void] (Get-7zip)
# Get Qt source file name from URL.
$QtSrcFileName = Split-Path -Leaf $QtSrcUrl
# If Qt version is not specified on the command line, try to extract the value.
if (-not $QtVersion) {
$QtVersion = $QtSrcFileName -replace "`.[^`.]*$",''
$QtVersion = $QtVersion -replace 'qt-',''
$QtVersion = $QtVersion -replace 'everywhere-',''
$QtVersion = $QtVersion -replace 'opensource-',''
$QtVersion = $QtVersion -replace 'src-',''
$QtVersion = $QtVersion -replace '-src',''
}
Write-Output "Building static Qt version $QtVersion"
# Qt installation directory.
$QtDir = "$QtStaticDir\$QtVersion"
# Get MinGW root directory, if not specified on the command line.
if (-not $MingwDir) {
# Search all instances of gcc.exe from C:\Qt prebuilt environment.
$GccList = #(Get-ChildItem -Path C:\Qt\Tools\mingw*\bin\gcc.exe | ForEach-Object FullName | Sort-Object)
if ($GccList.Length -eq 0) {
Exit-Script "MinGW environment not found, no Qt prebuilt version?"
}
$MingwDir = (Split-Path -Parent (Split-Path -Parent $GccList[$GccList.Length - 1]))
}
Write-Output "Using MinGW from $MingwDir"
# Build the directory tree where the static version of Qt will be installed.
Create-Directory $QtStaticDir\src
Create-Directory $QtDir
# Download the Qt source package if not yet done.
Download-File $QtSrcUrl $QtStaticDir\src\$QtSrcFileName
# Directory of expanded packages.
$QtSrcDir = "$QtStaticDir\src\$((Get-Item $QtStaticDir\src\$QtSrcFileName).BaseName)"
# Expand archives if not yet done
Expand-Archive $QtStaticDir\src\$QtSrcFileName $QtStaticDir\src $QtSrcDir
# Patch Qt's mkspecs for static build.
$File = "$QtSrcDir\qtbase\mkspecs\win32-g++\qmake.conf"
if (-not (Select-String -Quiet -SimpleMatch -CaseSensitive "# [QT-STATIC-PATCH]" $File)) {
Write-Output "Patching $File ..."
Copy-Item $File "$File.orig"
#"
# [QT-STATIC-PATCH]
QMAKE_LFLAGS += -static -static-libgcc
QMAKE_CFLAGS_RELEASE -= -O2
QMAKE_CFLAGS_RELEASE += -Os -momit-leaf-frame-pointer
DEFINES += QT_STATIC_BUILD
"# | Out-File -Append $File -Encoding Ascii
}
# Set a clean path including MinGW.
$env:Path = "$MingwDir\bin;$MingwDir\opt\bin"
# Force English locale to avoid weird effects of tools localization.
$env:LANG = "en"
# Set environment variable QT_INSTALL_PREFIX. Documentation says it should be
# used by configure as prefix but this does not seem to work. So, we will
# also specify -prefix option in configure.
$env:QT_INSTALL_PREFIX = $QtDir
# Configure, compile and install Qt.
Push-Location $QtSrcDir
& $env:SystemRoot\System32\cmd.exe /c "configure.bat -static -debug-and-release -platform win32-g++ -prefix $QtDir `
-qt-zlib -qt-pcre -qt-libpng -qt-libjpeg -qt-freetype -opengl desktop -qt-sql-sqlite -no-openssl `
-opensource -confirm-license `
-make libs -nomake tools -nomake examples -nomake tests"
mingw32-make -k -j4
mingw32-make -k install
Pop-Location
# Patch Qt's installed mkspecs for static build of application.
$File = "$QtDir\mkspecs\win32-g++\qmake.conf"
#"
CONFIG += static
"# | Out-File -Append $File -Encoding Ascii
Exit-Script
}
#-----------------------------------------------------------------------------
# A function to exit this script. The Message parameter is used on error.
#-----------------------------------------------------------------------------
function Exit-Script ([string]$Message = "")
{
$Code = 0
if ($Message -ne "") {
Write-Output "ERROR: $Message"
$Code = 1
}
if (-not $NoPause) {
pause
}
exit $Code
}
#-----------------------------------------------------------------------------
# Silently create a directory.
#-----------------------------------------------------------------------------
function Create-Directory ([string]$Directory)
{
[void] (New-Item -Path $Directory -ItemType "directory" -Force)
}
#-----------------------------------------------------------------------------
# Download a file if not yet present.
# Warning: If file is present but incomplete, do not download it again.
#-----------------------------------------------------------------------------
function Download-File ([string]$Url, [string]$OutputFile)
{
$FileName = Split-Path $Url -Leaf
if (-not (Test-Path $OutputFile)) {
# Local file not present, start download.
Write-Output "Downloading $Url ..."
try {
$webclient = New-Object System.Net.WebClient
$webclient.DownloadFile($Url, $OutputFile)
}
catch {
# Display exception.
$_
# Delete partial file, if any.
if (Test-Path $OutputFile) {
Remove-Item -Force $OutputFile
}
# Abort
Exit-Script "Error downloading $FileName"
}
# Check that the file is present.
if (-not (Test-Path $OutputFile)) {
Exit-Script "Error downloading $FileName"
}
}
}
#-----------------------------------------------------------------------------
# Get path name of 7zip, abort if not found.
#-----------------------------------------------------------------------------
function Get-7zip
{
$Exe = "C:\Program Files\7-Zip\7z.exe"
if (-not (Test-Path $Exe)) {
$Exe = "C:\Program Files (x86)\7-Zip\7z.exe"
}
if (-not (Test-Path $Exe)) {
Exit-Script "7-zip not found, install it first, see http://www.7-zip.org/"
}
$Exe
}
#-----------------------------------------------------------------------------
# Expand an archive file if not yet done.
#-----------------------------------------------------------------------------
function Expand-Archive ([string]$ZipFile, [string]$OutDir, [string]$CheckFile)
{
# Check presence of expected expanded file or directory.
if (-not (Test-Path $CheckFile)) {
Write-Output "Expanding $ZipFile ..."
& (Get-7zip) x $ZipFile "-o$OutDir" | Select-String -Pattern "^Extracting " -CaseSensitive -NotMatch
if (-not (Test-Path $CheckFile)) {
Exit-Script "Error expanding $ZipFile, $OutDir\$CheckFile not found"
}
}
}
#-----------------------------------------------------------------------------
# Execute main code.
#-----------------------------------------------------------------------------
. Main

How to include nmath.h?

I would like to include the header nmath.h for my C code (within an R package) to find R_FINITE and ML_ERR_return_NAN. I found that one cannot include nmath.h directly. For R_FINITE to be found, I could include R_ext/libextern.h. But I don't know what to include so that ML_ERR_return_NAN is found. Any ideas? I found here that Prof. Brian Ripley referred to Writing R Extensions, but I couldn't find nmath.h being addressed there (where exactly?)
On Debian or Ubuntu:
sudo apt-get install r-mathlib
after which you can build test programs such as this:
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4;
// compile-command: "gcc -s -Wall -O3 \
// -I/usr/share/R/include -o rmath_rnorm \
// rmath_rnorm.c -lRmath -lm" -*-
// Compare to
// $ Rscript -e "RNGkind('Marsaglia'); \
// .Random.seed[2:3] <- c(123L, 456L); rnorm(2)"
// [1] -0.2934974 -0.3343770
#include <stdio.h>
#define MATHLIB_STANDALONE 1
#include <Rmath.h>
int main(void) {
set_seed(123, 456);
printf("rnorm: %f %f\n", rnorm(0.0, 1.0), rnorm(0.0, 1.0));
return 0;
}
Note: The first four lines should be one-line in the file you safe, then M-x compile build the program for your. Ditto for the Rscript invocation: one line.
Edit: Drats. Answered the wrong question :) nmath.h appears to not be exported from src/nmath/nmath.h but this R Mathlibrary is what is exported by R Core for use by others. Where as the nmath.h file has
/* Private header file for use during compilation of Mathlib */
#ifndef MATHLIB_PRIVATE_H
#define MATHLIB_PRIVATE_H
so you are not supposed to rely on it.

Cross platform way of testing whether a file is a directory

Currently I have some code like (condensed and removed a bunch of error checking):
dp = readdir(dir);
if (dp->d_type == DT_DIR) {
}
This works swimmingly on my Linux machine. However on another machine (looks like SunOS, sparc):
SunOS HOST 5.10 Generic_127127-11 sun4u sparc SUNW,Ultra-5_10
I get the following error at compile time:
error: structure has no member named `d_type'
error: `DT_DIR' undeclared (first use in this function)
I thought the dirent.h header was crossplatform (for POSIX machines). Any suggestions.
Ref http://www.nexenta.org/os/Porting_Codefixes:
The struct dirent definition in solaris does not contain the d_type field. You would need to make the changes as follows
if (de->d_type == DT_DIR)
{
return 0;
}
changes to
struct stat s; /*include sys/stat.h if necessary */
..
..
stat(de->d_name, &s);
if (s.st_mode & S_IFDIR)
{
return 0;
}
Since stat is also POSIX standard it should be more cross-platform. But you may want to use if ((s.st_mode & S_IFMT) == S_IFDIR) to follow the standard.

Resources