From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id +Fa8F3TDBWByIgAAWB0awg (envelope-from ) for ; Mon, 18 Jan 2021 12:20:52 -0500 Received: by simark.ca (Postfix, from userid 112) id 5951F1EF80; Mon, 18 Jan 2021 12:20:52 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_NONE,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from sourceware.org (unknown [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 56D751E940 for ; Mon, 18 Jan 2021 12:20:51 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 13885388E824; Mon, 18 Jan 2021 17:20:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 13885388E824 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1610990451; bh=aY2Uej7k0THEMMK0iNjg66ThFEEEltz/WY18x6FMamY=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=L6FFIUld+E7eJdG8nSW3Wex+h8J/KM3gLm4J4/YPV46ZvACWiv/2QrI0MLx+PZVOa OxNN5EGXZmrpZfqPw2wcgR0FDuzp7wTrgSn9iQvEBnYb1QJSzIw7N7UbTlIbCQtr86 Kz9tNqymw0aUk/7mZzmNGi1jgZvUP6FFzGXSV7rM= Received: from smtp.gentoo.org (smtp.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) by sourceware.org (Postfix) with ESMTP id 8F58D384B822 for ; Mon, 18 Jan 2021 17:20:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 8F58D384B822 Received: from vapier.lan (localhost [127.0.0.1]) by smtp.gentoo.org (Postfix) with ESMTP id 7B9E3340BCD for ; Mon, 18 Jan 2021 17:20:46 +0000 (UTC) To: gdb-patches@sourceware.org Subject: [PATCH v2] sim: common: modernize gennltvals.sh Date: Mon, 18 Jan 2021 12:20:41 -0500 Message-Id: <20210118172041.725-1-vapier@gentoo.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20210117101044.32143-1-vapier@gentoo.org> References: <20210117101044.32143-1-vapier@gentoo.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Mike Frysinger via Gdb-patches Reply-To: Mike Frysinger Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" It's not 1996 anymore, so stop writing shell code like it is, and rewrite it with modern POSIX shell standards. This makes it much more user friendly. Then regenerate the file with latest newlib sources to verify. --- Here's what I pushed. And here's the final shellcheck warnings: In sim/common/gennltvals.sh line 87: printf "/* from %s */\n" ${files} ^------^ SC2086: Double quote to prevent globbing and word splitting. Did you mean: printf "/* from %s */\n" "${files}" In sim/common/gennltvals.sh line 97: printf '#include <%s>\n' ${files} ^------^ SC2086: Double quote to prevent globbing and word splitting. Did you mean: printf '#include <%s>\n' "${files}" For more information: https://www.shellcheck.net/wiki/SC2086 -- Double quote to prevent globbing ... sim/ChangeLog | 7 + sim/common/Makefile.in | 2 +- sim/common/gennltvals.sh | 321 ++++++++++++++++++++++++++++----------- sim/common/gentvals.sh | 74 --------- sim/common/nltvals.def | 7 + 5 files changed, 244 insertions(+), 167 deletions(-) delete mode 100755 sim/common/gentvals.sh diff --git a/sim/ChangeLog b/sim/ChangeLog index d8f530996e69..fd368d6d67f6 100644 --- a/sim/ChangeLog +++ b/sim/ChangeLog @@ -1,3 +1,10 @@ +2021-01-18 Mike Frysinger + + * Makefile.in (headers): Change args to gennltvals.sh. + * gennltvals.sh: Rewrite from scratch. + * gentvals.sh: Delete. + * nltvals.def: Regen. + 2021-01-15 Mike Frysinger * configure.ac: Delete AC_CONFIG_SUBDIRS(testsuite) call. diff --git a/sim/common/Makefile.in b/sim/common/Makefile.in index 4191b107e2fa..33cd788737cb 100644 --- a/sim/common/Makefile.in +++ b/sim/common/Makefile.in @@ -82,7 +82,7 @@ headers: rootme=`pwd` ; \ cd $(srcdir) ; \ rm -f nltvals.new ; \ - $(SHELL) $(abs_srcdir)/gennltvals.sh $(SHELL) $(srcroot) "$(CPP_FOR_TARGET)" > nltvals.new ; \ + $(SHELL) $(abs_srcdir)/gennltvals.sh --cpp "$(CPP_FOR_TARGET)" --srcroot $(srcroot) --output nltvals.new ; \ $(SHELL) $(srcroot)/move-if-change nltvals.new nltvals.def .c.o: diff --git a/sim/common/gennltvals.sh b/sim/common/gennltvals.sh index 79180335b627..005fa5b2368c 100755 --- a/sim/common/gennltvals.sh +++ b/sim/common/gennltvals.sh @@ -1,33 +1,137 @@ #! /bin/sh -# Generate nltvals.def, a file that describes various newlib/libgloss -# target values used by the host/target interface. +# Copyright (C) 1996-2021 Free Software Foundation, Inc. # -# Syntax: /bin/sh gennltvals.sh shell srcroot cpp - -shell=$1 -srcroot=$2 -cpp=$3 - -srccom=$srcroot/sim/common -if [ -d "${srcroot}/newlib" ]; then - # If newlib is manually in the same source tree, use it. - newlibroot=${srcroot} -else - # Else assume it's alongside the gdb/binutils repo. - newlibroot=${srcroot}/../newlib -fi - -echo '/* Newlib/libgloss macro values needed by remote target support. */' -echo '/* This file is machine generated by gennltvals.sh. */' - -$shell ${srccom}/gentvals.sh "" errno ${newlibroot}/newlib/libc/include \ - "errno.h sys/errno.h" 'E[[:upper:][:digit:]]*' "${cpp}" - -$shell ${srccom}/gentvals.sh "" signal ${newlibroot}/newlib/libc/include \ - "signal.h sys/signal.h" 'SIG[[:upper:][:digit:]]*' "${cpp}" - -$shell ${srccom}/gentvals.sh "" open ${newlibroot}/newlib/libc/include \ - "fcntl.h sys/fcntl.h sys/_default_fcntl.h" 'O_[[:upper:][:digit:]]*' "${cpp}" +# This file is part of the GNU simulators. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Display the tool usage and exit. +usage() { + cat < Write to the specified file instead of stdout. + --cpp The preprocessor to use. + --srcroot The root of this source tree. + -h, --help This text you're reading! +EOF + if [ $# -gt 0 ]; then + error "$*" + fi + exit 0 +} + +# Show an error message and exit. +error() { + echo "$0: error: $*" >&2 + exit 1 +} + +ARG_CPP="cpp" +ARG_SRCROOT="" +ARG_NEWLIB="" +ARG_OUTPUT="" + +# Emit the header for this generated def file. +gen_header() { + cat <\n' ${files} + for f in ${files}; do + sed -E -n -e "/^# *define[[:space:]]${pattern}/{\ + s|# *define[[:space:]](${pattern})[[:space:]]*([^[:space:]][^[:space:]]*).*$|\1|; \ + p}" \ + "${dir}/${f}" + done | + sort -u | + while read -r sym; do + echo "#ifdef ${sym}" + echo "DEFVAL { \"${sym}\", ${sym} }," + echo "#endif" + done + ) | + ${ARG_CPP} -E -I"${dir}" - | + sed -E -n -e '/^DEFVAL/{s/DEFVAL//; s/[[:space:]]+/ /; p}' + + if [ -z "${target}" ]; then + echo "/* end ${type} target macros */" + echo "#endif" + else + echo "/* end ${target} ${type} target macros */" + echo "#endif" + echo "#endif" + fi +} + +# Generate the common C library constants. No arch should override these. +gen_common() { + gentvals "" errno ${ARG_NEWLIB}/newlib/libc/include \ + "errno.h sys/errno.h" 'E[[:upper:][:digit:]]*' + + gentvals "" signal ${ARG_NEWLIB}/newlib/libc/include \ + "signal.h sys/signal.h" 'SIG[[:upper:][:digit:]]*' + + gentvals "" open ${ARG_NEWLIB}/newlib/libc/include \ + "fcntl.h sys/fcntl.h sys/_default_fcntl.h" 'O_[[:upper:][:digit:]]*' +} # Unfortunately, each newlib/libgloss port has seen fit to define their own # syscall.h file. This means that system call numbers can vary for each port. @@ -35,67 +139,100 @@ $shell ${srccom}/gentvals.sh "" open ${newlibroot}/newlib/libc/include \ # If you want to try to improve this, please do, but don't break anything. # Note that there is a standard syscall.h file (libgloss/syscall.h) now which # hopefully more targets can use. - -dir=libgloss target=bfin -$shell ${srccom}/gentvals.sh $target sys ${newlibroot}/$dir \ - "syscall.h" 'SYS_[_[:alnum:]]*' "${cpp}" - -dir=newlib/libc/sys/d10v/sys target=d10v -$shell ${srccom}/gentvals.sh $target sys ${newlibroot}/$dir \ - "syscall.h" 'SYS_[_[:alnum:]]*' "${cpp}" - -# OBSOLETE dir=libgloss target=d30v -# OBSOLETE $shell ${srccom}/gentvals.sh $target sys ${newlibroot}/$dir \ -# OBSOLETE "syscall.h" 'SYS_[_[:alnum:]]*' "${cpp}" - -dir=libgloss/cr16/sys target=cr16 -$shell ${srccom}/gentvals.sh $target sys ${newlibroot}/$dir \ - "syscall.h" 'SYS_[_[:alnum:]]*' "${cpp}" - -dir=libgloss target=fr30 -$shell ${srccom}/gentvals.sh $target sys ${newlibroot}/$dir \ - "syscall.h" 'SYS_[_[:alnum:]]*' "${cpp}" - -dir=libgloss target=frv -$shell ${srccom}/gentvals.sh $target sys ${newlibroot}/$dir \ - "syscall.h" 'SYS_[_[:alnum:]]*' "${cpp}" - -dir=libgloss/i960 target=i960 -$shell ${srccom}/gentvals.sh $target sys ${newlibroot}/$dir \ - "syscall.h" 'SYS_[_[:alnum:]]*' "${cpp}" - -dir=libgloss target=m32r -$shell ${srccom}/gentvals.sh $target sys ${newlibroot}/$dir \ - "syscall.h" 'SYS_[_[:alnum:]]*' "${cpp}" - -dir=libgloss/mcore target=mcore -$shell ${srccom}/gentvals.sh $target sys ${newlibroot}/$dir \ - "syscall.h" 'SYS_[_[:alnum:]]*' "${cpp}" - -dir=libgloss target=mn10200 -$shell ${srccom}/gentvals.sh $target sys ${newlibroot}/$dir \ - "syscall.h" 'SYS_[_[:alnum:]]*' "${cpp}" - -dir=libgloss target=mn10300 -$shell ${srccom}/gentvals.sh $target sys ${newlibroot}/$dir \ - "syscall.h" 'SYS_[_[:alnum:]]*' "${cpp}" - -dir=libgloss target=msp430 -$shell ${srccom}/gentvals.sh $target sys ${newlibroot}/$dir \ - "syscall.h" 'SYS_[_[:alnum:]]*' "${cpp}" - -dir=libgloss target=sparc -$shell ${srccom}/gentvals.sh $target sys ${newlibroot}/$dir \ - "syscall.h" 'SYS_[_[:alnum:]]*' "${cpp}" - -dir=libgloss/v850/sys target=v850 -$shell ${srccom}/gentvals.sh $target sys ${newlibroot}/$dir \ - "syscall.h" 'SYS_[_[:alnum:]]*' "${cpp}" - -dir=libgloss target=lm32 -$shell ${srccom}/gentvals.sh $target sys ${newlibroot}/$dir \ - "syscall.h" 'SYS_[_[:alnum:]]*' "${cpp}" - -dir=libgloss target=pru -$shell ${srccom}/gentvals.sh $target sys ${newlibroot}/$dir \ - "syscall.h" 'SYS_[_[:alnum:]]*' "${cpp}" +# +# NB: New ports should use libgloss, not newlib. +gen_arch() { + target="$1" + dir="${2:-libgloss}" + gentvals "${target}" sys "${ARG_NEWLIB}/${dir}" "syscall.h" 'SYS_[_[:alnum:]]*' +} + +gen_arches() { + gen_arch bfin + gen_arch d10v newlib/libc/sys/d10v/sys + gen_arch cr16 libgloss/cr16/sys + gen_arch fr30 + gen_arch frv + gen_arch i960 libgloss/i960 + gen_arch m32r + gen_arch mcore libgloss/mcore + gen_arch mn10200 + gen_arch mn10300 + gen_arch msp430 + gen_arch sparc + gen_arch v850 libgloss/v850/sys + gen_arch lm32 + gen_arch pru +} + +# Process the script command line options. +parse_opts() { + while [ $# -gt 0 ]; do + case $1 in + --cpp) + ARG_CPP="$2" + shift + ;; + -o|--output) + ARG_OUTPUT="$2" + shift + ;; + --srcroot) + ARG_SRCROOT="$2" + shift + ;; + -h|--help) + usage + ;; + --) + shift + break + ;; + -*) + usage "unknown option: $1" + ;; + *) + break + ;; + esac + shift + done + + if [ $# -gt 2 ]; then + error "too many arguments: $*" + elif [ $# -eq 1 ]; then + ARG_NEWLIB="$1" + fi + + # Try to find newlib relative to our source tree. + if [ -z "${ARG_NEWLIB}" ]; then + if [ -z "${ARG_SRCROOT}" ]; then + ARG_SRCROOT="$(dirname "$0")/../.." + fi + if [ -d "${ARG_SRCROOT}/newlib" ]; then + # If newlib is manually in the same source tree, use it. + ARG_NEWLIB="${ARG_SRCROOT}/newlib" + elif [ -d "${ARG_SRCROOT}/../newlib" ]; then + # Or see if it's alongside the gdb/binutils repo. + ARG_NEWLIB="${ARG_SRCROOT}/../newlib" + else + error "unable to find newlib" + fi + fi +} + +main() { + # The error checking isn't perfect, but should be good enough for this script. + set -e + + parse_opts "$@" + + if [ -n "${ARG_OUTPUT}" ]; then + exec >"${ARG_OUTPUT}" || exit 1 + fi + + gen_header + gen_common + gen_arches +} +main "$@" diff --git a/sim/common/gentvals.sh b/sim/common/gentvals.sh deleted file mode 100755 index 6dd7315f30aa..000000000000 --- a/sim/common/gentvals.sh +++ /dev/null @@ -1,74 +0,0 @@ -#!/bin/sh -# Usage: gentvals.sh target type dir files pattern cpp - -target=$1 -type=$2 -dir=$3 -# FIXME: Would be nice to process #include's in these files. -files=$4 -pattern=$5 -cpp=$6 - -# FIXME: need trap to remove tmp files. - -rm -f tmpvals.list tmpvals.uniq -for f in $files -do - if test -f $dir/$f ; then - grep "#define[ ]$pattern" $dir/$f | sed -e "s/^.*#define[ ]\($pattern\)[ ]*\([^ ][^ ]*\).*$/\1/" >> tmpvals.list - fi -done - -sort tmpvals.uniq - -rm -f tmpvals.h -for f in $files -do - if test -f $dir/$f ; then - echo "#include <$f>" >>tmpvals.h - fi -done - -cat tmpvals.uniq | -while read sym -do - echo "#ifdef $sym" >>tmpvals.h - echo 'DEFVAL { "'$sym'", '$sym ' },' >>tmpvals.h - echo "#endif" >>tmpvals.h -done - -if test -z "$target" -then - echo "#ifdef ${type}_defs" -else - echo "#ifdef NL_TARGET_$target" - echo "#ifdef ${type}_defs" -fi - -for f in $files -do - if test -f $dir/$f ; then - echo "/* from $f */" - fi -done - -if test -z "$target" -then - echo "/* begin $type target macros */" -else - echo "/* begin $target $type target macros */" -fi - -$cpp -I$dir tmpvals.h | grep DEFVAL | sed -e 's/DEFVAL//' -e 's/ / /' - -if test -z "$target" -then - echo "/* end $type target macros */" - echo "#endif" -else - echo "/* end $target $type target macros */" - echo "#endif" - echo "#endif" -fi - -rm -f tmpvals.list tmpvals.uniq tmpvals.h diff --git a/sim/common/nltvals.def b/sim/common/nltvals.def index 92ccc9aded8b..08df7d5c4598 100644 --- a/sim/common/nltvals.def +++ b/sim/common/nltvals.def @@ -115,6 +115,7 @@ { "SIGPROF", 27 }, { "SIGQUIT", 3 }, { "SIGSEGV", 11 }, + { "SIGSTKSZ", 8192 }, { "SIGSTOP", 17 }, { "SIGSYS", 12 }, { "SIGTERM", 15 }, @@ -138,12 +139,18 @@ /* begin open target macros */ { "O_ACCMODE", (0|1|2) }, { "O_APPEND", 0x0008 }, + { "O_CLOEXEC", 0x40000 }, { "O_CREAT", 0x0200 }, + { "O_DIRECT", 0x80000 }, + { "O_DIRECTORY", 0x200000 }, { "O_EXCL", 0x0800 }, + { "O_EXEC", 0x400000 }, { "O_NOCTTY", 0x8000 }, + { "O_NOFOLLOW", 0x100000 }, { "O_NONBLOCK", 0x4000 }, { "O_RDONLY", 0 }, { "O_RDWR", 2 }, + { "O_SEARCH", 0x400000 }, { "O_SYNC", 0x2000 }, { "O_TRUNC", 0x0400 }, { "O_WRONLY", 1 }, -- 2.28.0