File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -203,7 +203,38 @@ static const char *get_runpath() {
203203 return NULL ;
204204 }
205205}
206-
206+ // If DT_RUNPATH is not accessable, use the first search path as alternative.
207+ #elif defined(__unix__ ) || defined(__unix )
208+ static const char * get_runpath () {
209+ void * handle = dlopen (NULL , RTLD_NOW );
210+ if (handle == NULL ) {
211+ return NULL ;
212+ }
213+ Dl_serinfo serinfo ;
214+ if (dlinfo (handle , RTLD_DI_SERINFOSIZE , & serinfo ) == -1 ) {
215+ return NULL ;
216+ }
217+ _cleanup_free_ Dl_serinfo * sip = (Dl_serinfo * )malloc (serinfo .dls_size );
218+ if (dlinfo (handle , RTLD_DI_SERINFOSIZE , sip ) == -1 ) {
219+ return NULL ;
220+ }
221+ if (dlinfo (handle , RTLD_DI_SERINFO , sip ) == -1 ) {
222+ return NULL ;
223+ }
224+ size_t len = strlen (sip -> dls_serpath [0 ].dls_name );
225+ char * runpath = strdup (sip -> dls_serpath [0 ].dls_name );
226+ for (size_t i = 1 ; i < serinfo .dls_cnt ; i ++ ) {
227+ len = len + 1 /* SEP */ + strlen (sip -> dls_serpath [i ].dls_name ) + 1 ;
228+ char * tmp = realloc (runpath , len * sizeof (char ));
229+ if (tmp == NULL ) {
230+ return NULL ;
231+ }
232+ strcat (tmp , ":" );
233+ strcat (tmp , sip -> dls_serpath [i ].dls_name );
234+ runpath = tmp ;
235+ }
236+ return runpath ;
237+ }
207238#else
208239// FIXME: I still didn't find the way to determine RUNPATH on non-Linux.
209240// So use $ORIGIN as a temporary solution
You can’t perform that action at this time.
0 commit comments