haproxy/dev
Willy Tarreau ca773e1a2a DEV: ncpu: make the wrapper work both as a lib and executable
It's convenient to have a share lib be able to also work as a wrapper.
But recent glibc broke support for this dual-mode thing some time ago:

   https://patchwork.ozlabs.org/project/glibc/patch/20190312130235.8E82C89CE49C@oldenburg2.str.redhat.com/
   https://stackoverflow.com/questions/59074126/loading-executable-or-executing-a-library

Trying to preload such an executable indeed returns:

   ERROR: ld.so: object '/path/to/ncpu.so' from LD_PRELOAD cannot be preloaded (cannot dynamically load position-independent executable): ignored.

Note that the code still supports it since libc.so is both an executable
and a lib. The approach taken here is the same as in the nousr.so wrapper.
It consists in dropping the DF_1_PIE flag from the resulting executable
since it's what the dynamic linker is looking for. This flag is found in
FLAGS_1 in the .dynamic section. As readelf -a suggests, it's after the
tag 0x6ffffffb. The value is 0x08000000. We're using objdump to figure the
length and offset of the struct, dd to extract the 3 parts, and sed to
patch the binary.

It's likely that it will only work on 64-bit little endian, though tests
should be performed to see what to do on other platforms. At least on
x86_64, ld.so is happy and it continues to be possible to use the binary
as a .so, and that the platform where most of the development happens so
that's fine.

In any case the wrapper and the standard shared lib are still made two
distinct files so that it's possible to use the non-patched version on
unsupported OSes or architectures.
2025-01-08 11:27:10 +01:00
..
base64 CONTRIB: move some dev-specific tools to dev/ 2021-04-02 17:48:42 +02:00
coccinelle DEV: coccinelle: add a test to detect unchecked calloc() 2024-08-24 19:13:56 +02:00
flags DEV: lags/show-sess-to-flags: Properly handle fd state on server side 2024-11-25 21:57:30 +01:00
gdb DEV: gdb: add a number of gdb scripts to navigate in core dumps 2024-10-28 17:55:08 +01:00
h2 DEV: h2: support hex-encoded data sequences in mkhdr 2024-01-12 18:59:59 +01:00
haring MEDIUM: ring: use the topmost bit of the tail as a lock 2024-03-25 17:34:19 +00:00
hpack DEV: hpack: fix trash build regression 2023-01-27 10:22:20 +01:00
ncpu DEV: ncpu: make the wrapper work both as a lib and executable 2025-01-08 11:27:10 +01:00
patchbot DEV: patchbot: prepare for new version 3.2-dev 2024-11-26 17:24:21 +01:00
phash DEV: phash: Update 414 and 431 status codes to phash 2024-11-19 15:29:40 +01:00
plug_qdisc CONTRIB: move some dev-specific tools to dev/ 2021-04-02 17:48:42 +02:00
poll DEV: poll: add support for epoll 2022-11-25 17:07:22 +01:00
qpack MINOR: qpack: implement standalone decoder tool 2022-06-15 15:42:10 +02:00
sslkeylogger DEV: sslkeylogger: handle file opening error 2023-10-03 15:23:35 +02:00
tcploop DEV: tcploop: add minimal support for unix sockets 2023-01-11 11:27:20 +01:00
trace CONTRIB: move some dev-specific tools to dev/ 2021-04-02 17:48:42 +02:00
udp BUILD: address a few remaining calloc(size, n) cases 2024-02-10 11:37:27 +01:00