Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Wed, 28 Feb 2024 13:37:00 -0500
From: Rich Felker <dalias@...c.org>
To: Max Filippov <jcmvbkbc@...il.com>
Cc: musl@...ts.openwall.com
Subject: Re: Initial xtensa/fdpic port review

On Wed, Feb 28, 2024 at 01:30:32PM -0500, Rich Felker wrote:
> On Wed, Feb 28, 2024 at 09:20:33AM -0800, Max Filippov wrote:
> > 
> > > >               p->relocated = 1;
> > > >       }
> > > > @@ -1485,7 +1487,7 @@ void __libc_exit_fini()
> > > >               if (dyn[0] & (1<<DT_FINI_ARRAY)) {
> > > >                       size_t n = dyn[DT_FINI_ARRAYSZ]/sizeof(size_t);
> > > >                       size_t *fn = (size_t *)laddr(p, dyn[DT_FINI_ARRAY])+n;
> > > > -                     while (n--) ((void (*)(void))*--fn)();
> > > > +                     while (n--) fpaddr(p, *--fn)();
> > >
> > > If this is fixable on the tooling side it really should be fixed
> > > there. init/fini arrays should have actual language-level function
> > > addresses (descriptor addresses on fdpic), not instruction addresses.
> > 
> > I read libgcc code at
> >   https://github.com/jcmvbkbc/gcc-xtensa/blob/xtensa-14-8789-fdpic/libgcc/crtstuff.c#L498-L503
> > and the way it's written suggests that this was done on purpose.
> > I put it into the WIP pile to figure out later what the purpose was.
> > I thought that SH might not have this issue because it just didn't
> > use the .array_init/.array_fini.
> 
> I'm pretty sure we're using it -- musl-cross-make always forces it on
> via the gcc configure command line -- but it's possible there's some
> override disabling it for sh. I'll try some test cases and confirm
> whether sh is doing it right. Maybe the arm folks will have input on
> this too..?

Confirmed both that it works, and that it's working via init_array.
GCC emits:

	.section        .init_array,"aw"
	.align 2
	.long   foo@...CDESC

for

	__attribute__((__constructor__))
	void foo() { ... }

Also, FWIW, I believe there's something of an application-facing
contract that you can declare function pointer arrays with
__attribute__((__section__(".init_array"))) and have them work, which
would not work if instruction addresses rather than function addresses
are expected to be there.

Rich

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.