From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/7637 Path: news.gmane.org!not-for-mail From: Szabolcs Nagy Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH v3] Build process uses script to add CFI directives to x86 asm Date: Wed, 13 May 2015 21:22:52 +0200 Message-ID: <20150513192252.GF31118@port70.net> References: <1431539679-4265-1-git-send-email-alexinbeijing@gmail.com> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1431544995 7743 80.91.229.3 (13 May 2015 19:23:15 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 13 May 2015 19:23:15 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-7649-gllmg-musl=m.gmane.org@lists.openwall.com Wed May 13 21:23:10 2015 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1YscFH-0001ZG-8T for gllmg-musl@m.gmane.org; Wed, 13 May 2015 21:23:07 +0200 Original-Received: (qmail 9995 invoked by uid 550); 13 May 2015 19:23:05 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 9973 invoked from network); 13 May 2015 19:23:04 -0000 Mail-Followup-To: musl@lists.openwall.com Content-Disposition: inline In-Reply-To: <1431539679-4265-1-git-send-email-alexinbeijing@gmail.com> User-Agent: Mutt/1.5.23 (2014-03-12) Xref: news.gmane.org gmane.linux.lib.musl.general:7637 Archived-At: * Alex Dowad [2015-05-13 19:54:39 +0200]: > > I've noticed that using tempfiles for the augmented asm has a drawback: > In the source file/line debugging info generated by the assembler, it records > the source file as "/tmp/". Then, when you try to debug a program > which is linked against the resulting musl, GDB tries to open "/tmp/" > to show in the source window. > > Suggestions?? Perhaps generate .cfi.s files as Szabolcs suggested?? > you can use .file "foo.s" > diff --git a/Makefile b/Makefile > index 6559295..9aefd62 100644 > --- a/Makefile > +++ b/Makefile > @@ -118,7 +118,7 @@ $(foreach s,$(wildcard src/*/$(ARCH)*/*.s),$(eval $(call mkasmdep,$(s)))) > $(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $(dir $<)$(shell cat $<) > > %.o: $(ARCH)/%.s > - $(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $< > + tools/aswrap.sh $< $@ $(ARCH) "$(CC) $(CFLAGS_ALL_STATIC)" > i think passing down the build command that way is not ok " may be used inside CFLAGS (and there are other shell quote issues) it hides the build command in the make output it's not clear if the build correctly handles if CC fails > +function get_const1() { > + # for instructions with 2 operands, get 1st operand (assuming it is constant) > + match($0, /-?(0x[0-9a-fA-F]+|[0-9]+),/) > + return parse_const(substr($0, RSTART, RLENGTH-1)) > +} it only matches with immediate , i'd just clean the whitespaces up so you dont have to add \s* or \s+ to every regex (see below) awk converts strings to numbers, but hex is unfortunately not guaranteed to be supported (otherwise strtod conversion rules apply) but you can implement parse_const(s) as sign = sub(/^-/,"",s) hex = sub(/^0x/,"",s) if (hex) n = hex2int(s) else n = s+0 return sign ? -n : n this does not handle binary (0b11) and octal (0123) asm consts (i think you should check for those and emit a warning). > + > +{ print } > + i'd do it something like { # print original line print # avoid generating .cfi based on comments gsub(/(#|\/\/).*/,"") # canonicalize whitespaces gsub(/\s+/," ") gsub(/ *, */,",") gsub(/ *: */,": ") sub(/ $/,"") sub(/^ /,"") # dont do anything with string consts if ($0 ~ /^\.(ascii|str).*"/) next # possibly handle /**/ and multiline string consts (split by \) # if you dont want to do that then check for it and print warning if ($0 ~ /\/\*/ || $0 ~ /\\/) print ARGV[0] ": warning: unhandled asm: " $0 > "/dev/stderr" } > +/^.global\s+\w+/ { > + globals[$2] = 1 may be spelt as .globl too > +} > +/pushl?/ { > + if (match($0, /\s+%(ax|bx|cx|dx|di|si|bp|sp)/)) > + adjust_sp_offset(2) > + else > + adjust_sp_offset(4) > +} i think pushl $123 push $123 are different > diff --git a/tools/aswrap.sh b/tools/aswrap.sh > new file mode 100755 > index 0000000..0afbd4e > --- /dev/null > +++ b/tools/aswrap.sh > @@ -0,0 +1,15 @@ > +#!/bin/sh > +# Run assembler to produce an object file, optionally applying other pre-processing steps > +input=$1 > +output=$2 > +arch=$3 > +as=$4 > + > +if [ -f "tools/add-cfi.awk.$arch" ]; then > + tmpfile=$(mktemp -t musl-aswrap-XXXXXX) > + awk -f tools/add-cfi.awk.$arch $input >$tmpfile > + mv $tmpfile $tmpfile.s > + input=$tmpfile.s > +fi set LC_ALL=C because you depend on collation order in the awk script or use [[:alnum:]] etc in the regex > +$as -c -o $output $input > \ No newline at end of file add new lines at the end