unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Florian Weimer <fw@deneb.enyo.de>
To: Sandra Loosemore <sandra@codesourcery.com>
Cc: Joseph Myers <joseph@codesourcery.com>,
	 Florian Weimer <fweimer@redhat.com>,
	 <libc-alpha@sourceware.org>,
	 Szabolcs Nagy <szabolcs.nagy@arm.com>,
	 <cltang@codesourcery.com>,  <andrew@codesourcery.com>
Subject: Re: [review v3] slotinfo in struct dtv_slotinfo_list should be flexible array [BZ #25...
Date: Tue, 12 Nov 2019 19:42:19 +0100	[thread overview]
Message-ID: <87r22dey2c.fsf@mid.deneb.enyo.de> (raw)
In-Reply-To: <4e7ad8ea-43ae-6af6-d2a9-2a05d42b0cc6@codesourcery.com> (Sandra Loosemore's message of "Tue, 12 Nov 2019 10:42:39 -0700")

* Sandra Loosemore:

> I don't have any state on this particular change or what it is trying to 
> accomplish, but the linker error is the sort of thing that happens when 
> the compiler sees a reference to an object it thinks will be put in the 
> small data section, but the actual definition of the object puts it 
> somewhere else (e.g., because it is too big for small data) -- in this 
> case the .bss section.  Are there conflicting declarations about the 
> size of the object?  If that's unavoidable for some reason, another way 
> to suppress GP-relative addressing on this object would be to give it an 
> explicit .bss section attribute everywhere it's declared.

Thanks for providing this information.  Here is a small reproducer:

enum { size = 100 };

struct flexible
{
  int length;
  int data[];
};

struct inflexible
{
  int length;
  int data[size];
};

static struct flexible flexible =
  {
   .data = { [size - 1] = 0, }
  };

static struct inflexible inflexible =
  {
   .data = { [size - 1] = 0, }
  };

struct flexible *
get_flexible (void)
{
  return &flexible;
}

struct inflexible *
get_inflexible (void)
{
  return &inflexible;
}

It results in:

	.file	"t.c"
	.section	.text
	.align	2
	.global	get_flexible
	.type	get_flexible, @function
get_flexible:
	addi	r2, gp, %gprel(flexible)
	ret
	.size	get_flexible, .-get_flexible
	.align	2
	.global	get_inflexible
	.type	get_inflexible, @function
get_inflexible:
	movhi	r2, %hiadj(inflexible)
	addi	r2, r2, %lo(inflexible)
	ret
	.size	get_inflexible, .-get_inflexible
	.section	.bss
	.type	inflexible, @object
	.size	inflexible, 404
	.align	2
inflexible:
	.zero	404
	.type	flexible, @object
	.size	flexible, 404
	.align	2
flexible:
	.zero	404
	.ident	"GCC: (GNU) 9.2.1 20191101 [gcc-9-branch revision 277712]"

I think this shows that the backend uses the static type size (as in
sizeof) to determine whether an object goes into the small data
section, not the allocated object size.

The linker only sees the allocated object size, so it places the
object wrongly (although it could perhaps do something smarter because
it can see the relocations).

If the object is not placed into .bss, the choice of .sdata vs .data
is also based on the static type size, so that would need fixing too.

I don't know how to work around that in the source code.  My
preference would be to fix the backend.  I guess we could back out the
commit and disable the warning for GCC 10 instead.

  parent reply	other threads:[~2019-11-12 18:42 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-03 17:11 [review] slotinfo in struct dtv_slotinfo_list should be flexible array [BZ #25 Florian Weimer (Code Review)
2019-11-06 16:12 ` Szabolcs Nagy
2019-11-06 16:21   ` Florian Weimer
2019-11-11 15:09     ` Szabolcs Nagy
2019-11-11 15:12       ` Florian Weimer
2019-11-11 21:41         ` Sergio Durigan Junior
2019-11-12 10:22           ` Szabolcs Nagy
2019-11-12 10:35             ` Florian Weimer
2019-11-09 11:44 ` [review v2] " Florian Weimer (Code Review)
2019-11-12 10:40 ` Szabolcs Nagy (Code Review)
2019-11-12 11:47 ` [review v3] " Florian Weimer (Code Review)
2019-11-12 17:29   ` Joseph Myers
2019-11-12 17:42     ` Sandra Loosemore
2019-11-12 18:04       ` Joseph Myers
2019-11-12 18:42       ` Florian Weimer [this message]
2019-11-12 20:59         ` Sandra Loosemore
2019-11-13  5:47           ` Florian Weimer
2019-11-13 16:04             ` Sandra Loosemore
2019-11-13 16:25               ` Florian Weimer
2019-11-13 16:06             ` Jeff Law
2019-11-12 22:14         ` Carlos O'Donell
2019-11-12 22:18           ` Florian Weimer
2019-11-12 22:24             ` Carlos O'Donell
2019-11-12 22:26               ` Florian Weimer
2019-11-12 22:39               ` Joseph Myers
2019-11-13  6:18                 ` Florian Weimer
2019-11-13 16:05             ` Jeff Law
2019-11-12 23:12           ` Sandra Loosemore
2019-11-12 23:15             ` Joseph Myers
2019-11-12 12:53 ` Szabolcs Nagy (Code Review)
2019-11-12 13:00 ` [pushed] " Sourceware to Gerrit sync (Code Review)
2019-11-12 13:00 ` Sourceware to Gerrit sync (Code Review)

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

  List information: https://www.gnu.org/software/libc/involved.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87r22dey2c.fsf@mid.deneb.enyo.de \
    --to=fw@deneb.enyo.de \
    --cc=andrew@codesourcery.com \
    --cc=cltang@codesourcery.com \
    --cc=fweimer@redhat.com \
    --cc=joseph@codesourcery.com \
    --cc=libc-alpha@sourceware.org \
    --cc=sandra@codesourcery.com \
    --cc=szabolcs.nagy@arm.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.
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 read-only IMAP folder(s) and NNTP newsgroup(s).