From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Subject: Re: [PATCH v3] Build process uses script to add CFI directives to x86 asm
Date: Wed, 13 May 2015 22:57:20 -0400 [thread overview]
Message-ID: <20150514025720.GB17573@brightrain.aerifal.cx> (raw)
In-Reply-To: <20150513192252.GF31118@port70.net>
On Wed, May 13, 2015 at 09:22:52PM +0200, Szabolcs Nagy wrote:
> * Alex Dowad <alexinbeijing@gmail.com> [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/<random-garbage>". Then, when you try to debug a program
> > which is linked against the resulting musl, GDB tries to open "/tmp/<random-garbage>"
> > to show in the source window.
> >
> > Suggestions?? Perhaps generate .cfi.s files as Szabolcs suggested??
> >
>
> you can use
>
> .file "foo.s"
One question -- will the fact that the line numbers don't match up
interfere with debugging? If so, the CFI generation should add the
directives to existing lines separated by ;'s rather than inserting
lines.
> > 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
The quoting is probably off, but otherwise it doesn't look so bad.
> " 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
Do you have a better design in mind?
> > +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).
Is 0b something that could even be relied upon? We generally use a
minimal asm dialect without extensions that real or hypothetical
alternate assemblers might not have. I'm happy with a YAGNI approach
to the CFI generation.
> > +/^.global\s+\w+/ {
> > + globals[$2] = 1
>
> may be spelt as .globl too
Yes, that might be used somewhere.
> > +/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
How so? Likewise I don't think the stuff for 2-byte push/pop is
terribly useful. It's not a meaningful operation to be performing in
32-bit code.
Rich
next prev parent reply other threads:[~2015-05-14 2:57 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-13 17:54 Alex Dowad
2015-05-13 19:22 ` Szabolcs Nagy
2015-05-14 2:57 ` Rich Felker [this message]
2015-05-14 10:25 ` Szabolcs Nagy
2015-05-15 17:31 Alex Dowad
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150514025720.GB17573@brightrain.aerifal.cx \
--to=dalias@libc.org \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).