All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Vladimir 'φ-coder/phcoder' Serbinenko" <phcoder@gmail.com>
To: David Woodhouse <dwmw2@infradead.org>
Cc: The development of GRUB 2 <grub-devel@gnu.org>, llvmdev@cs.uiuc.edu
Subject: Re: clang .code16 with -Os producing larger code that it needs to
Date: Fri, 20 Feb 2015 16:46:54 +0100	[thread overview]
Message-ID: <54E756EE.1030401@gmail.com> (raw)
In-Reply-To: <1424446685.5437.52.camel@infradead.org>

[-- Attachment #1: Type: text/plain, Size: 1810 bytes --]

On 20.02.2015 16:38, David Woodhouse wrote:
> On Fri, 2015-02-20 at 15:58 +0100, Vladimir 'φ-coder/phcoder' Serbinenko
> wrote:
>> When experimenting with compiling GRUB2 with clang using integrated as,
>> I found out that it generates a 16-bit code bigger than gas counterpart
>> and result gets too big for size constraints of bootsector. This was
>> traced mainly to 2 problems.
> 
> ...
> 
>> 32-bit access to 16-bit addresses.
>> clang:
>>     7cbc:	67 66 8b 1d 5c 7c 00 00	addr32 mov 0x7c5c,%ebx
>> gas:
>>     7cbc:	66 8b 1e 5c 7c       	mov    0x7c5c,%ebx
> 
>> 32-bit jump.
>> clang:
>> +    7cb5:	66 0f 83 07 01 00 00 	jae    7dc3 <L_floppy_probe>
>> gas:
>> -    7cb5:	0f 83 0a 01          	jae    7dc3 <L_floppy_probe>
> 
> To a large extent, those are the *same* problem. We don't know that it's
> eventually going to fit into a 16-bit offset, so we emit it with a fixup
> record which can cope with 32 bits.
> 
All labels are local to the source file. If I use %eax instead of %ebx
in first example I get the short code. For the second example how does
clang detect that offset fits into one byte for issuing EB XX sequence
which is issued in resulting file in several places. Can we use the same
mechanism to detect when issuing 16-bit reference and keep 32-bit one
for external references?
> Arguably, the jump is *particularly* gratuitous in many cases... but in
> 'big real' mode is the IP *really* limited to 16 bits?
> 
> We could make it default to 16-bit, as gas does. But then we'd be
> screwed in the cases where we really *do* need 32-bit.
> 
> What we actually need to do is implement handling for the explicit
> addr32 prefix. Then we can do what gas does and default to 16-bit but
> *also* have a way to do 32-bit when it's needed.
> 



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 213 bytes --]

  reply	other threads:[~2015-02-20 15:47 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-20 14:58 clang .code16 with -Os producing larger code that it needs to Vladimir 'φ-coder/phcoder' Serbinenko
2015-02-20 15:26 ` Vladimir 'φ-coder/phcoder' Serbinenko
2015-02-20 15:38 ` David Woodhouse
2015-02-20 15:46   ` Vladimir 'φ-coder/phcoder' Serbinenko [this message]
2015-02-20 16:05     ` David Woodhouse
2015-02-20 16:18       ` David Woodhouse
2015-02-20 18:47         ` [LLVMdev] " Rafael Espíndola
2015-02-23 12:07           ` David Woodhouse
2015-02-24  8:42             ` Craig Topper
2015-02-24  9:07               ` David Woodhouse

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=54E756EE.1030401@gmail.com \
    --to=phcoder@gmail.com \
    --cc=dwmw2@infradead.org \
    --cc=grub-devel@gnu.org \
    --cc=llvmdev@cs.uiuc.edu \
    /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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.