DYLD_PRINT_LIBRARIES not working
Asked Answered
P

1

4

Trying to experiment with other DYLD_ properties I've found that jvm is manipulating with properties and they are ignored during execution.
My Java test:

class Env {
    public static void main(String... args) {
        System.getenv().entrySet().stream().forEach(e -> System.out.println(e.getKey() + " = " + e.getValue()));
    }
}

Invocation:

$ export DYLD_PRINT_LIBRARIES=1
$ export MY_PRINT_LIBRARIES=2
$ javac Env.java && java Env|grep PRINT
MY_PRINT_LIBRARIES = 2
$ 

On the other side, my C test:

#include <stdio.h>

int main(int argc, char **argv, char **envp) {
    while (*envp) {
        printf("%s\n", *envp);
        envp++;
    }
    return 0;
}

Invocation:

$ gcc env.c && ./a.out|grep PRINT
dyld: loaded: /Users/okutane/test/java/./a.out
dyld: loaded: /usr/lib/libSystem.B.dylib
dyld: loaded: /usr/lib/system/libcache.dylib
...
dyld: loaded: /usr/lib/libc++.1.dylib
dyld: loaded: /usr/lib/libDiagnosticMessagesClient.dylib
MY_PRINT_LIBRARIES=2
DYLD_PRINT_LIBRARIES=1
$

I expected jvm test to work too, is there are any workaround?

Provencher answered 21/9, 2016 at 18:19 Comment(0)
K
8

With the introduction of SIP, all environment variables matching DYLD_* will be stripped before executing a restricted binary. That includes the /usr/bin/java binary you would be using:

$ ls -lOL /usr/bin/java
-rwxr-xr-x  1 root  wheel  restricted,compressed 58560 Sep  7 06:41 /usr/bin/java*
Kavita answered 25/11, 2016 at 17:34 Comment(2)
Any way around this?Insufficient
It depends on what you actually want to achieve. Maybe you are actually looking for java -Djava.library.path=...? However, to get DYLD_* variables working with /usr/bin/java, you would need to completely disable SIP.Kavita

© 2022 - 2024 — McMap. All rights reserved.