about summary refs log tree commit diff
path: root/scripts
diff options
context:
space:
mode:
authorSergey Bugaev <bugaevc@gmail.com>2023-04-29 23:18:21 +0300
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2023-05-01 01:21:23 +0200
commit2bc516020ff8642d1352e99f0f25fef002457079 (patch)
treed46fceedf2452b7ca63272d3fcb00aab45135630 /scripts
parente6136c693970bd641cc526cbe204d02c0c3ba0e4 (diff)
downloadglibc-2bc516020ff8642d1352e99f0f25fef002457079.tar.gz
glibc-2bc516020ff8642d1352e99f0f25fef002457079.tar.xz
glibc-2bc516020ff8642d1352e99f0f25fef002457079.zip
hurd: Make it possible to call memcpy very early
Normally, in static builds, the first code that runs is _start, in e.g.
sysdeps/x86_64/start.S, which quickly calls __libc_start_main, passing
it the argv etc. Among the first things __libc_start_main does is
initializing the tunables (based on env), then CPU features, and then
calls _dl_relocate_static_pie (). Specifically, this runs ifunc
resolvers to pick, based on the CPU features discovered earlier, the
most suitable implementation of "string" functions such as memcpy.

Before that point, calling memcpy (or other ifunc-resolved functions)
will not work.

In the Hurd port, things are more complex. In order to get argv/env for
our process, glibc normally needs to do an RPC to the exec server,
unless our args/env are already located on the stack (which is what
happens to bootstrap processes spawned by GNU Mach). Fetching our
argv/env from the exec server has to be done before the call to
__libc_start_main, since we need to know what our argv/env are to pass
them to __libc_start_main.

On the other hand, the implementation of the RPC (and other initial
setup needed on the Hurd before __libc_start_main can be run) is not
very trivial. In particular, it may (and on x86_64, will) use memcpy.
But as described above, calling memcpy before __libc_start_main can not
work, since the GOT entry for it is not yet initialized at that point.

Work around this by pre-filling the GOT entry with the baseline version
of memcpy, __memcpy_sse2_unaligned. This makes it possible for early
calls to memcpy to just work. The initial value of the GOT entry is
unused on x86_64, and changing it won't interfere with the relocation
being performed later: once _dl_relocate_static_pie () is called, the
baseline version will get replaced with the most suitable one, and that
is what subsequent calls of memcpy are going to call.

Checked on x86_64-gnu.

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
Message-Id: <20230429201822.2605207-6-bugaevc@gmail.com>
Diffstat (limited to 'scripts')
0 files changed, 0 insertions, 0 deletions