Skip to content

Commit 09e392a

Browse files
committed
Removing netbsd license dependency
1 parent d7a892e commit 09e392a

File tree

1 file changed

+7
-158
lines changed

1 file changed

+7
-158
lines changed

lldb/source/Host/common/Host.cpp

Lines changed: 7 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -349,168 +349,16 @@ bool Host::ResolveExecutableInBundle(FileSpec &file) { return false; }
349349
#include <stdio.h>
350350
extern char **p_xargv;
351351

352-
/* Fix missing Dl_info & dladdr in AIX
353-
* The code is taken from netbsd.org (src/crypto/external/bsd/openssl/dist/crypto/dso/dso_dlfcn.c)
354-
* except strlcpy & strlcat (those are taken from openbsd.org (src/lib/libc/string))
355-
*/
356-
/*-
357-
* See IBM's AIX Version 7.2, Technical Reference:
358-
* Base Operating System and Extensions, Volume 1 and 2
359-
* https://www.ibm.com/support/knowledgecenter/ssw_aix_72/com.ibm.aix.base/technicalreferences.htm
360-
*/
361-
#include <sys/ldr.h>
362-
#include <errno.h>
363-
364-
/* strlcpy:
365-
* Copy string src to buffer dst of size dsize. At most dsize-1
366-
* chars will be copied. Always NUL terminates (unless dsize == 0).
367-
* Returns strlen(src); if retval >= dsize, truncation occurred.
368-
*/
369-
size_t strlcpy(char *dst, const char *src, size_t dsize)
370-
{
371-
const char *osrc = src;
372-
size_t nleft = dsize;
373-
374-
/* Copy as many bytes as will fit. */
375-
if (nleft != 0) {
376-
while (--nleft != 0) {
377-
if ((*dst++ = *src++) == '\0') {
378-
break;
379-
}
380-
}
381-
}
382-
383-
/* Not enough room in dst, add NUL and traverse rest of src. */
384-
if (nleft == 0) {
385-
if (dsize != 0) {
386-
*dst = '\0'; /* NUL-terminate dst */
387-
}
388-
while (*src++) {
389-
;
390-
}
391-
}
392-
393-
return src - osrc - 1; /* count does not include NUL */
394-
}
395-
396-
/* strlcat:
397-
* Appends src to string dst of size dsize (unlike strncat, dsize is the
398-
* full size of dst, not space left). At most dsize-1 characters
399-
* will be copied. Always NUL terminates (unless dsize <= strlen(dst)).
400-
* Returns strlen(src) + MIN(dsize, strlen(initial dst)).
401-
* If retval >= dsize, truncation occurred.
402-
*/
403-
size_t strlcat(char *dst, const char *src, size_t dsize)
404-
{
405-
const char *odst = dst;
406-
const char *osrc = src;
407-
size_t n = dsize;
408-
size_t dlen;
409-
410-
/* Find the end of dst and adjust bytes left but don't go past end. */
411-
while (n-- != 0 && *dst != '\0') {
412-
dst++;
413-
}
414-
dlen = dst - odst;
415-
n = dsize - dlen;
416-
417-
if (n-- == 0) {
418-
return dlen + strlen(src);
419-
}
420-
while (*src != '\0') {
421-
if (n != 0) {
422-
*dst++ = *src;
423-
n--;
424-
}
425-
src++;
426-
}
427-
*dst = '\0';
428-
429-
return dlen + src - osrc; /* count does not include NUL */
430-
}
431-
432-
/* ~ 64 * (sizeof(struct ld_info) + _XOPEN_PATH_MAX + _XOPEN_NAME_MAX) */
433-
# define DLFCN_LDINFO_SIZE 86976
434-
typedef struct Dl_info {
435-
const char *dli_fname;
436-
} Dl_info;
437-
/*
438-
* This dladdr()-implementation will also find the ptrgl (Pointer Glue) virtual
439-
* address of a function, which is just located in the DATA segment instead of
440-
* the TEXT segment.
441-
*/
442-
static int dladdr(const void *ptr, Dl_info *dl)
443-
{
444-
uintptr_t addr = (uintptr_t)ptr;
445-
struct ld_info *ldinfos;
446-
struct ld_info *next_ldi;
447-
struct ld_info *this_ldi;
448-
449-
if ((ldinfos = (struct ld_info *)malloc(DLFCN_LDINFO_SIZE)) == NULL) {
450-
dl->dli_fname = NULL;
451-
return 0;
452-
}
453-
454-
if ((loadquery(L_GETINFO, (void *)ldinfos, DLFCN_LDINFO_SIZE)) < 0) {
455-
/*-
456-
* Error handling is done through errno and dlerror() reading errno:
457-
* ENOMEM (ldinfos buffer is too small),
458-
* EINVAL (invalid flags),
459-
* EFAULT (invalid ldinfos ptr)
460-
*/
461-
free((void *)ldinfos);
462-
dl->dli_fname = NULL;
463-
return 0;
464-
}
465-
next_ldi = ldinfos;
466-
467-
do {
468-
this_ldi = next_ldi;
469-
if (((addr >= (uintptr_t)this_ldi->ldinfo_textorg)
470-
&& (addr < ((uintptr_t)this_ldi->ldinfo_textorg +
471-
this_ldi->ldinfo_textsize)))
472-
|| ((addr >= (uintptr_t)this_ldi->ldinfo_dataorg)
473-
&& (addr < ((uintptr_t)this_ldi->ldinfo_dataorg +
474-
this_ldi->ldinfo_datasize)))) {
475-
char *buffer = NULL;
476-
char *member = NULL;
477-
size_t buffer_sz;
478-
size_t member_len;
479-
480-
buffer_sz = strlen(this_ldi->ldinfo_filename) + 1;
481-
member = this_ldi->ldinfo_filename + buffer_sz;
482-
if ((member_len = strlen(member)) > 0) {
483-
buffer_sz += 1 + member_len + 1;
484-
}
485-
if ((buffer = (char *)malloc(buffer_sz)) != NULL) {
486-
strlcpy(buffer, this_ldi->ldinfo_filename, buffer_sz);
487-
if (member_len > 0) {
488-
/*
489-
* Need to respect a possible member name and not just
490-
* returning the path name in this case. See docs:
491-
* sys/ldr.h, loadquery() and dlopen()/RTLD_MEMBER.
492-
*/
493-
strlcat(buffer, "(", buffer_sz);
494-
strlcat(buffer, member, buffer_sz);
495-
strlcat(buffer, ")", buffer_sz);
496-
}
497-
dl->dli_fname = buffer;
498-
}
499-
break;
500-
} else {
501-
next_ldi = (struct ld_info *)((uintptr_t)this_ldi +
502-
this_ldi->ldinfo_next);
503-
}
504-
} while (this_ldi->ldinfo_next);
505-
free((void *)ldinfos);
506-
return dl->dli_fname != NULL;
507-
}
508-
509352
#endif
510353

511354
FileSpec Host::GetModuleFileSpecForHostAddress(const void *host_addr) {
512355
FileSpec module_filespec;
513356
#ifdef _AIX
357+
// TODO: As the current AIX LLDB is static, we don't need dladdr which is
358+
// only for shared library, Below is the hack to find the module name
359+
// for static LLDB
360+
// FIXME: If LLDB is later built as shared library, we have to find the way simillar to dladdr
361+
// since AIX does not support the dladdr API.
514362
if (host_addr == reinterpret_cast<void *>(HostInfoBase::ComputeSharedLibraryDirectory)) {
515363
// FIXME: AIX dladdr return "lldb" for this case
516364
if (p_xargv[0]) {
@@ -519,7 +367,7 @@ FileSpec Host::GetModuleFileSpecForHostAddress(const void *host_addr) {
519367
return module_filespec;
520368
}
521369
}
522-
#endif
370+
#else
523371
#if !defined(__ANDROID__)
524372
Dl_info info;
525373
if (::dladdr(host_addr, &info)) {
@@ -528,6 +376,7 @@ FileSpec Host::GetModuleFileSpecForHostAddress(const void *host_addr) {
528376
FileSystem::Instance().Resolve(module_filespec);
529377
}
530378
}
379+
#endif
531380
#endif
532381
return module_filespec;
533382
}

0 commit comments

Comments
 (0)