mailing list of musl libc
 help / color / mirror / code / Atom feed
* optopt in getopt not being set, only when building with OpenWrt
@ 2018-11-16  9:54 Paul Sykes
  2018-11-16 21:11 ` Szabolcs Nagy
  0 siblings, 1 reply; 3+ messages in thread
From: Paul Sykes @ 2018-11-16  9:54 UTC (permalink / raw)
  To: musl

Hi,

First post to the list, apologies in advance for any etiquette transgressions.

On my OpenWrt builds I found that the optopt variable was never set
when calling the function getopt. I tested the same code on my desktop
using the gcc wrapper and optopt was set as expected.

Debugging showed that optopt was being set correctly in getopt.c
however the variable was not being set in my calling code.

Adding optopt to the file 'dynamic.list' resolved the issue when
building with OpenWrt. I noticed that all the other extern variables
for getopt appear in dynamic.list except optopt.

Paul.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: optopt in getopt not being set, only when building with OpenWrt
  2018-11-16  9:54 optopt in getopt not being set, only when building with OpenWrt Paul Sykes
@ 2018-11-16 21:11 ` Szabolcs Nagy
  2018-11-16 21:38   ` Rich Felker
  0 siblings, 1 reply; 3+ messages in thread
From: Szabolcs Nagy @ 2018-11-16 21:11 UTC (permalink / raw)
  To: musl; +Cc: Paul Sykes

* Paul Sykes <paulsykes@gmail.com> [2018-11-16 17:54:23 +0800]:
> On my OpenWrt builds I found that the optopt variable was never set
> when calling the function getopt. I tested the same code on my desktop
> using the gcc wrapper and optopt was set as expected.
> 
> Debugging showed that optopt was being set correctly in getopt.c
> however the variable was not being set in my calling code.
> 
> Adding optopt to the file 'dynamic.list' resolved the issue when
> building with OpenWrt. I noticed that all the other extern variables
> for getopt appear in dynamic.list except optopt.

yeah the dynamic list entry is needed so the address of the
object internally in the libc is the same as in the main
executable in case of copy relocation (only matters for
dynamic linked executables and pie executable may work
since that does not require copy relocs).

all targets with copy relocs are affected, but only musl
version 1.1.20 has the problem i think.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: optopt in getopt not being set, only when building with OpenWrt
  2018-11-16 21:11 ` Szabolcs Nagy
@ 2018-11-16 21:38   ` Rich Felker
  0 siblings, 0 replies; 3+ messages in thread
From: Rich Felker @ 2018-11-16 21:38 UTC (permalink / raw)
  To: musl, Paul Sykes

On Fri, Nov 16, 2018 at 10:11:00PM +0100, Szabolcs Nagy wrote:
> * Paul Sykes <paulsykes@gmail.com> [2018-11-16 17:54:23 +0800]:
> > On my OpenWrt builds I found that the optopt variable was never set
> > when calling the function getopt. I tested the same code on my desktop
> > using the gcc wrapper and optopt was set as expected.
> > 
> > Debugging showed that optopt was being set correctly in getopt.c
> > however the variable was not being set in my calling code.
> > 
> > Adding optopt to the file 'dynamic.list' resolved the issue when
> > building with OpenWrt. I noticed that all the other extern variables
> > for getopt appear in dynamic.list except optopt.

Yes, this is exactly right. It seems to have been an oversight. I'll
push a fix for inclusion in 1.1.21, and distros using 1.1.20 should
apply it since this is a notable regression. However,

> yeah the dynamic list entry is needed so the address of the
> object internally in the libc is the same as in the main
> executable in case of copy relocation (only matters for
> dynamic linked executables and pie executable may work
> since that does not require copy relocs).
> 
> all targets with copy relocs are affected, but only musl
> version 1.1.20 has the problem i think.

On distros using default-pie, the impact might be low, depending on
arch, gcc version, and CFLAGS. There's never a *need* to use copy
relocations with pie, and at one point gcc never did, but I think with
current tooling it's more complicated whether copy relocations get
used or not.

Rich


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-11-16 21:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-16  9:54 optopt in getopt not being set, only when building with OpenWrt Paul Sykes
2018-11-16 21:11 ` Szabolcs Nagy
2018-11-16 21:38   ` Rich Felker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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 NNTP newsgroup(s).