This is the mail archive of the mailing list for the binutils project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PATCH: PR ld/16428: Disallow -shared/-pie, -shared/-static, -pie/-static

>> Are there "no" versions of these options? In gold, once any of these
>> options is set, it can't be unset.
> In effect, yes.  -static has these synonyms:
>         -a archive
>         -Bstatic
>         -dn
>         -non_shared
> and these antonyms:
>         -a shared
>         -a default
>         -Bdynamic
>         -call_shared
>         -dy
> What's more, these options in part imply -static:
>         -N / -omagic
>         -n / -nmagic
>         -r / --relocatable
>         -Ur

These options (the ones gold supports, at least) act a bit differently
in gold (I'm withholding judgment whether this is good or bad).

The -r, -static, -shared, and -pie options select an output format,
and you can't pick more than one of them (exception: -r -static is
OK). The -n/-N options imply -static. The -Bstatic and -Bdynamic
options (aka -dn and -dy) control what libraries we search for, but
don't force an output format.

In the absence of any output format options, we'll pick -static or
-shared based on whether we see any input shared libraries, so
-Bstatic and -Bdynamic can have an indirect effect on the output
format, but they're not synonyms for -static and -dynamic.

> I do not see the point in adding a boolean that singles out one or two
> of these options for a warning, when the rest of the linker operates
> according to the final state these options leave input_flags.dynamic.
> Quite clearly if "-static -pie" is nonsense, then so is "-Bstatic -pie".

If -static and -Bstatic truly are synonyms, then I agree.

> Also, I don't see why we should disallow something like
> LD="ld -static" LDFLAGS="-pie -Bdynamic".

It seems to me a philosophical question of whether mutually exclusive
options should be disallowed, or whether later ones should override
earlier ones. Your example with LDFLAGS is a good argument for the
latter, but I don't think we've ever received any complaints that you
can't do that with gold.

> I see no reason why "-static -pie" should not work.  "-static" does
> *not* specify the type of output directly.  "-static" chooses input
> objects.  "-pie" affects output.  The two options are logically
> orthogonal.  You ought to be able to build a PIE that doesn't use any
> shared libraries!  If it doesn't work, then we have a bug elsewhere.

Well, in gold, -Bstatic -pie is fine -- that asks to build a PIE with
just archive libraries, but the output is still going to be an ET_DYN.
In practice, at least in the ELF world, PIE binaries are dynamic even
if they have no dependencies on shared libraries.

Based on what you've said, I'm inclined to agree with you about Gnu
ld, though. As long as ld doesn't get into any internal inconsistency
if given seemingly conflicting options (e.g., if "-static -dynamic"
always means "-dynamic"), there seems to be little reason to add the
checking. I guess it's a matter of whether that's more likely to be a
mistake that needs a diagnostic, or a convenience where LDFLAGS can
override a setting hardcoded into the Makefile.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]