Fix handling of null stap semaphores
According to the SystemTap documentation on user-space probes[0], stap
probe points without semaphores are denoted by setting the semaphore
address in the probe's note to zero. At present the code does do a
comparison of the semaphore address against zero, but only after it's
been relocated; as such it will (almost?) always fail, commonly
resulting in GDB trying to overwrite the ELF magic located at the
image's base address.
This commit tests the address as specified in the SDT note rather than
the relocated value in order to correctly detect absent probe
semaphores.
[0]: https://sourceware.org/systemtap/wiki/UserSpaceProbeImplementation
gdb/Changelog:
2020-01-11 George Barrett <bob@bob131.so>
* stap-probe.c (stap_modify_semaphore): Don't check for null
semaphores.
(stap_probe::set_semaphore, stap_probe::clear_semaphore): Check
for null semaphores.
gdb/testsuite/ChangeLog:
2020-01-11 George Barrett <bob@bob131.so>
* gdb.base/stap-probe.c (relocation_marker): Add dummy variable
to help in finding the image relocation offset.
* gdb.base/stap-probe.exp (stap_test): Accept arbitrary compile
options in arguments.
(stap_test_no_debuginfo): Likewise.
(stap-probe-nosem-noopt-pie, stap-probe-nosem-noopt-nopie): Add
test variants.
(stap_test): Add null semaphore relocation test.