Program Tip

Linux에서 현재 rpath를 검사하는 방법이 있습니까?

programtip 2020. 11. 19. 21:56
반응형

Linux에서 현재 rpath를 검사하는 방법이 있습니까?


readelf -d <elf> | grep RPATH쉘에서 주어진 바이너리를 검사하는 데 사용할 수 있다는 것을 알고 있지만 프로세스 내에서이 작업을 수행 할 수 있습니까?

(내가 완전히 구성한 시스템 호출) :

  /* get a copy of current rpath into buffer */
  sys_get_current_rpath(&buffer);

코드베이스에서 의심스러운 SO 링크 문제를 진단하려고 시도하고 있으며 가능하면 RPATH를 검사하고 싶습니다 (차라리 외부 스크립트를 생성 할 필요가 없습니다).


#include <stdio.h>
#include <elf.h>
#include <link.h>

int main()
{
  const ElfW(Dyn) *dyn = _DYNAMIC;
  const ElfW(Dyn) *rpath = NULL;
  const char *strtab = NULL;
  for (; dyn->d_tag != DT_NULL; ++dyn) {
    if (dyn->d_tag == DT_RPATH) {
      rpath = dyn;
    } else if (dyn->d_tag == DT_STRTAB) {
      strtab = (const char *)dyn->d_un.d_val;
    }
  }

  if (strtab != NULL && rpath != NULL) {
    printf("RPATH: %s\n", strtab + rpath->d_un.d_val);
  }
  return 0;
}

기록을 위해 rpath헤더 를 표시하는 몇 가지 명령이 있습니다.

objdump -x binary-or-library |grep RPATH

더 나은 방법은 다음과 같습니다.

readelf -d binary-or-library |head -20

두 번째 명령은 다른 라이브러리에 대한 직접적인 종속성과 rpath.


다음을 사용할 수도 있습니다.

chrpath -l binary-or-library

참고 URL : https://stackoverflow.com/questions/2836330/is-there-a-way-to-inspect-the-current-rpath-on-linux

반응형