This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc 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] aarch64: Check PIC instead of SHARED in start.S


On 10/6/17, Szabolcs Nagy <szabolcs.nagy@arm.com> wrote:
> On 04/10/17 10:05, H.J. Lu wrote:
>> On 10/3/17, Szabolcs Nagy <szabolcs.nagy@arm.com> wrote:
>>>
>>> it seems weak extern symbol is accessed via got and at
>>> link time that is not relaxed to 0 with -static -pie
>>> and the got entry is not initialized to 0 either.
>>
>> Please try the current hjl/pie/static branch.  I added Pcrt1.o to
>> to create static PIE.  There is no weak extern symbol anymore.
>> As long as there is no dynamic relocation before
>> _dl_relocate_static_pie relocates static PIE, it should work.
>>
>
> i still get weak undefined symbols (pthread stuff when linking
> without -lpthread)

All weak undefined symbols in static executable should be resolved
to zero at link-time, PIE nor non-PIE.  See

/* Is a undefined weak symbol which is resolved to 0.  Reference to an
   undefined weak symbol is resolved to 0 when building executable if
   it isn't dynamic and
   1. Has non-GOT/non-PLT relocations in text section.  Or
   2. Has no GOT/PLT relocation.
   Local undefined weak symbol is always resolved to 0.
 */
#define UNDEFINED_WEAK_RESOLVED_TO_ZERO(INFO, EH) \
  ((EH)->elf.root.type == bfd_link_hash_undefweak		 \
   && (SYMBOL_REFERENCES_LOCAL_P ((INFO), &(EH)->elf)		 \
       || (bfd_link_executable (INFO)				 \
	   && (!(EH)->has_got_reloc				 \
	       || (EH)->has_non_got_reloc))))

in elfxx-x86.h.  Also see:

https://sourceware.org/bugzilla/show_bug.cgi?id=19636

> how Pcrt1.o is supposed to work? it seems it is built the same
> way as crt1.o? (i'd expect Pcrt1 to mean "static pie link with
> pie libc.a", and crt1.o to mean "link executable that will be
> relocated by a dynamic linker")

That is correct:

[hjl@gnu-efi-2 glibc]$ readelf -sW csu/Pcrt1.o  | grep _dl_relocate_static_pie
[hjl@gnu-efi-2 glibc]$ readelf -sW csu/crt1.o  | grep _dl_relocate_static_pie
    24: 0000000000000038     4 FUNC    GLOBAL HIDDEN     2
_dl_relocate_static_pie
[hjl@gnu-efi-2 glibc]$

When Pcrt1.o is used, the real _dl_relocate_static_pie in libc.a will
be used for
static PIE.  Otherwise, you will get a dummy _dl_relocate_static_pie in crt1.o
for non-PIE static and dynamic executables.

-- 
H.J.


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