delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/12/19/08:40:15

Date: Mon, 19 Dec 94 04:50 MST
From: mat AT ardi DOT com (Mat Hostetter)
To: djgpp AT sun DOT soe DOT clarkson DOT edu
Subject: `.align' directive doesn't seem to work properly

My understanding is that this code should align `my_label' mod 8
bytes.  Instead, `my_label' is 0x11C4 after linking!  (with gcc -O;
0x11BC without -O).  The .o file seems to be fine; the problem seems
to happen at the link stage.  Using different align parameters will
affect where `my_label' ends up, but its alignment is relative to a
particular address and is not absolute.

One reason that this matters is that aligning loop branch targets mod 16
on the 80486 can greatly speed code (because of the way the 80486 code
prefetch buffers work).

Here's my test program; hopefully it will do the same thing for you.
You can confirm its results with `nm'.


#include <stdio.h>

int
main (int argc, char *argv[])
{
  extern char my_label;
  if (argc == 123)  /* Skip the asm but don't let gcc optimize it away. */
    asm (".align 8\n"
         "_my_label:");
  printf ("0x%lX\n", (unsigned long)&my_label);
  return 0;
}

-Mat

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019