Bug 87795 - Excessive alignment permitted for functions and labels
Summary: Excessive alignment permitted for functions and labels
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 9.0
: P3 normal
Target Milestone: 9.0
Assignee: Martin Sebor
URL:
Keywords: accepts-invalid, ice-on-invalid-code, patch
: 87794 (view as bug list)
Depends on:
Blocks:
 
Reported: 2018-10-29 16:46 UTC by pkoning
Modified: 2024-04-09 04:45 UTC (History)
3 users (show)

See Also:
Host:
Target: pdp11-aout
Build:
Known to work: 9.0
Known to fail: 8.2.0
Last reconfirmed: 2018-10-30 00:00:00


Attachments
variable and function alignment test case (102 bytes, text/plain)
2018-10-29 16:47 UTC, pkoning
Details
label alignment test case (64 bytes, text/plain)
2018-10-29 16:48 UTC, pkoning
Details

Note You need to log in before you can comment on or make changes to this bug.
Description pkoning 2018-10-29 16:46:59 UTC
Variable alignment is checked against MAX_OFILE_ALIGNMENT but function and label (-falign-label=n) alignment is not.  This causes requests to the target code to generate alignment directives that the output format doesn't support, causing ICE at least in some targets.
The attached testalign.c gets an error (on i386) for variable "ag", and on pdp11 also for variable "a4" (since max alignment on pdp11 is 2 bytes).  But the corresponding function alignments do not generate error messages.  
File testalign2.c with -falign-labels=n also passes the requested alignment to the back end without checking it against MAX_OFILE_ALIGNMENT.
Comment 1 pkoning 2018-10-29 16:47:36 UTC
Created attachment 44923 [details]
variable and function alignment test case
Comment 2 pkoning 2018-10-29 16:48:27 UTC
Created attachment 44924 [details]
label alignment test case
Comment 3 Andreas Schwab 2018-10-29 17:19:37 UTC
*** Bug 87794 has been marked as a duplicate of this bug. ***
Comment 4 Joel Sherrill 2018-10-29 17:48:57 UTC
I added myself as a CC because I want to see if these become errors or warnings. For core parts of RTEMS, I can see wanting these to be errors since it indicates we did something in core OS code that did not achieve the desired results. But in application code, it might not be as well considered or necessary.

So ultimately, it's a hard decision on how to treat mistakes in alignment requests
Comment 5 Martin Sebor 2018-10-30 00:13:15 UTC
Confirmed.  I get the following output with a pdp11-aout configured cross-compiler:

$ cat t.c && gcc -S -O2 -Wall t.c

int a2 __attribute__ ((aligned (2)));
int a4 __attribute__ ((aligned (4)));
int ag __attribute__ ((aligned (65536)));

void f2(void) __attribute__ ((aligned (2)));
void f4(void) __attribute__ ((aligned (4)));
void fg(void) __attribute__ ((aligned (65536)));

void f2(void) {}
void f4(void) {}
void fg(void) {}

t.c:2:5: error: alignment of ‘a4’ is greater than maximum object file alignment 2
    2 | int a4 __attribute__ ((aligned (4)));
      |     ^~
t.c:3:5: error: alignment of ‘ag’ is greater than maximum object file alignment 2
    3 | int ag __attribute__ ((aligned (65536)));
      |     ^~


After removing the variable declarations I get an ICE:

during RTL pass: final
t.c: In function ‘f4’:
t.c:6:1: internal compiler error: in assemble_start_function, at varasm.c:1801
    6 | void f4(void) {}
      | ^~~~
0x1345817 assemble_start_function(tree_node*, char const*)
	/ssd/src/gcc/svn/gcc/varasm.c:1801
0xaf2550 rest_of_handle_final
	/ssd/src/gcc/svn/gcc/final.c:4645
0xaf28c2 execute
	/ssd/src/gcc/svn/gcc/final.c:4723
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
Comment 6 pkoning 2018-10-30 16:34:30 UTC
(In reply to Joel Sherrill from comment #4)
> I added myself as a CC because I want to see if these become errors or
> warnings. For core parts of RTEMS, I can see wanting these to be errors
> since it indicates we did something in core OS code that did not achieve the
> desired results. But in application code, it might not be as well considered
> or necessary.

Interesting point.  The current case that is rejected (alignment of variables) is an error, so for consistency I'd say the other cases should do likewise.

If there is a desire to make too-large alignment into a warning, that might be better handled as a separate issue.  It could be a switch of some sort.  If changes are made, they should apply consistently to alignment of all kinds.
Comment 7 Martin Sebor 2018-10-30 21:40:59 UTC
Patch: https://gcc.gnu.org/ml/gcc-patches/2018-10/msg01965.html
Comment 8 Martin Sebor 2018-11-09 17:18:19 UTC
Author: msebor
Date: Fri Nov  9 17:17:47 2018
New Revision: 265977

URL: https://gcc.gnu.org/viewcvs?rev=265977&root=gcc&view=rev
Log:
PR c/87795 - Excessive alignment permitted for functions and labels

gcc/c-family/ChangeLog:

	PR c/87795
	* c-common.c (check_user_alignment): Use MAX_OFILE_ALIGNMENT.

gcc/testsuite/ChangeLog:

	PR c/87795
	* gcc.dg/attr-aligned.c: New test.


Added:
    trunk/gcc/testsuite/gcc.dg/attr-aligned.c
Modified:
    trunk/gcc/c-family/ChangeLog
    trunk/gcc/c-family/c-attribs.c
    trunk/gcc/c-family/c-common.c
    trunk/gcc/c-family/c-common.h
    trunk/gcc/c/c-decl.c
    trunk/gcc/doc/tm.texi
    trunk/gcc/doc/tm.texi.in
    trunk/gcc/testsuite/ChangeLog
Comment 9 Martin Sebor 2018-11-09 17:19:25 UTC
Fixed for GCC 9 in 265977.