I am trying to make our program runnable on some old Linux versions. One common import that prevents it is __longjmp_chk
, added in glibc 2.11 but missing in older ones. One "solution" is to use -D_FORTIFY_SOURCE=0
but this turns off other fortify functions (__printf_chk
etc) which are present in the target libc. Is there a way to make __longjmp_chk
a "weak import" which would use the function from libc.so.6
if present, and fall back to local stub if not?
Asked
Active
Viewed 327 times
2

Igor Skochinsky
- 24,629
- 2
- 72
- 109
2 Answers
1
Is there a way to make
__longjmp_chk
a "weak import" which would use the function fromlibc.so.6
if present, and fall back to local stub if not?
I'd say yes, using dlsym()
to check for __longjmp_chk
and acting accordingly:
/* cc -ldl */
#define _GNU_SOURCE
#include <setjmp.h>
#include <stdio.h>
#include <dlfcn.h>
void __longjmp_chk(sigjmp_buf env, int val)
{
void (*p)(sigjmp_buf, int) = dlsym(RTLD_NEXT, "__longjmp_chk");
if (p)
printf("use the function from libc\n"),
p(env, val);
else
{
printf("falling back to local stub\n");
/* local stub - whatever that may be */
}
}
main()
{ // try it
sigjmp_buf env;
while (!setjmp(env)) __longjmp_chk(env, 1);
return 0;
}

Armali
- 18,255
- 14
- 57
- 171
0
I am trying to make our program runnable on some old Linux versions.
There are only a few ways to make this work, and most of them are enumerated here.
Is there a way to make __longjmp_chk a "weak import".
No.

Community
- 1
- 1

Employed Russian
- 199,314
- 34
- 295
- 362