gprofng: fix build problems on linux-musl

ino64_t, off64_t, fpos64_t, stat64, __u64 are not defined on linux-musl.
Fixed by declaring these types for linux-musl.

2023-12-21  Vladimir Mezentsev  <vladimir.mezentsev@oracle.com>

	PR gprofng/30779
	PR gprofng/29593
	* common/gp-defs.h: Define ino64_t, off64_t, fpos64_t for linux-musl.
	* libcollector/unwind.c: Define __u64 for linux-musl.
	* src/util.h: Define dbe_stat_t.
	* src/ClassFile.cc: Use dbe_stat_t instead of "struct stat64".
	* src/Dbe.cc: Likewise.
	* src/DbeFile.cc: Likewise.
	* src/DbeFile.h: Likewise.
	* src/DbeSession.cc: Likewise.
	* src/Experiment.cc: Likewise.
	* src/checks.cc: Likewise.
	* src/util.cc: Likewise.
This commit is contained in:
Vladimir Mezentsev 2023-12-21 21:33:58 -08:00
parent 62544b0cf1
commit 576d2c97d8
11 changed files with 41 additions and 25 deletions

View File

@ -63,4 +63,10 @@
# endif
#endif
#if defined(__MUSL_LIBC)
#define ino64_t ino_t
#define off64_t off_t
#define fpos64_t fpos_t
#endif
#endif

View File

@ -231,6 +231,10 @@ memory_error_func (int status ATTRIBUTE_UNUSED, bfd_vma addr ATTRIBUTE_UNUSED,
}
#elif ARCH(Aarch64)
#if defined(__MUSL_LIBC)
typedef uint64_t __u64;
#endif
#define FILL_CONTEXT(context) \
{ CALL_UTIL (getcontext) (context); \
context->uc_mcontext.sp = (__u64) __builtin_frame_address(0); \

View File

@ -1006,7 +1006,7 @@ ClassFile::openFile (const char *fname)
append_msg (CMSG_ERROR, GTXT ("Cannot open file %s"), fname);
return;
}
struct stat64 stat_buf;
dbe_stat_t stat_buf;
if ((fstat64 (fd, &stat_buf) == -1) || (stat_buf.st_size == 0))
{
close (fd);

View File

@ -271,7 +271,7 @@ dbeGetFileAttributes (const char *filename, const char *format)
if (!strcmp (format, NTXT ("/bin/ls -dl ")))
{
// A kind of "/bin/ls -dl " simulation
struct stat64 sbuf;
dbe_stat_t sbuf;
sbuf.st_mode = 0;
dbe_stat (filename, &sbuf);
if (S_IREAD & sbuf.st_mode)

View File

@ -512,7 +512,7 @@ DbeFile::find_in_classpath (char *filename, Vector<DbeFile*> *classPath)
}
}
struct stat64 *
dbe_stat_t *
DbeFile::get_stat ()
{
if (sbuf.st_atim.tv_sec == 0)
@ -529,8 +529,8 @@ DbeFile::compare (DbeFile *df)
{
if (df == NULL)
return false;
struct stat64 *st1 = get_stat ();
struct stat64 *st2 = df->get_stat ();
dbe_stat_t *st1 = get_stat ();
dbe_stat_t *st2 = df->get_stat ();
if (st1 == NULL || st2 == NULL)
return false;
if (st1->st_size != st2->st_size)

View File

@ -67,7 +67,7 @@ public:
char *get_location (bool find_needed = true);
char *getResolvedPath ();
char *get_location_info ();
struct stat64 *get_stat ();
dbe_stat_t *get_stat ();
bool compare (DbeFile *df);
void set_need_refind (bool val);
void set_location (const char *filename);
@ -79,7 +79,7 @@ public:
bool inArchive;
int filetype;
struct stat64 sbuf;
dbe_stat_t sbuf;
DbeFile *container;
char *orig_location;
Experiment *experiment;

View File

@ -1169,7 +1169,7 @@ DbeSession::open_experiment (Experiment *exp, char *path)
t_exp_list[j] = NULL;
char *lineage_name = exp_names->fetch (j);
struct stat64 sbuf;
dbe_stat_t sbuf;
char *dpath = dbe_sprintf (NTXT ("%s/%s"), path, lineage_name);
// look for experiments with no profile collected

View File

@ -1631,7 +1631,7 @@ Experiment::open (char *path)
return status;
// Get creation time for experiment
struct stat64 st;
dbe_stat_t st;
if (dbe_stat (path, &st) == 0)
mtime = st.st_mtime;
@ -5594,7 +5594,7 @@ Experiment::find_expdir (char *path)
{
// This function checks that the experiment directory
// is of the proper form, and accessible
struct stat64 sbuf;
dbe_stat_t sbuf;
// Save the name
expt_name = dbe_strdup (path);
@ -5703,7 +5703,7 @@ Experiment::get_descendants_names ()
if (entry->d_name[0] == '_' || strncmp (entry->d_name, "M_r", 3) == 0)
{
char *dpath = dbe_sprintf (NTXT ("%s/%s"), dir_name, entry->d_name);
struct stat64 sbuf;
dbe_stat_t sbuf;
if (dbe_stat (dpath, &sbuf) == 0 && S_ISDIR (sbuf.st_mode))
exp_names->append (dpath);
else
@ -5727,7 +5727,7 @@ Experiment::create_dir (char *dname)
{
return true;
}
struct stat64 sbuf;
dbe_stat_t sbuf;
if (dbe_stat (dname, &sbuf) != 0 || S_ISDIR (sbuf.st_mode) == 0)
{
char *buf = dbe_sprintf (GTXT ("Unable to create directory `%s'\n"),
@ -6515,7 +6515,7 @@ Experiment::copy_file_to_archive (const char *name, const char *aname, int hide_
}
close (fd_w);
struct stat64 s_buf;
dbe_stat_t s_buf;
if (fstat64 (fd_r, &s_buf) == 0)
{
struct utimbuf u_buf;
@ -6703,7 +6703,7 @@ Experiment::copy_file_to_common_archive (const char *name, const char *aname,
return 1;
}
// Set read-only permissions
struct stat64 statbuf;
dbe_stat_t statbuf;
if (0 == dbe_stat_file (name, &statbuf))
{
mode_t mask = S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;

View File

@ -223,7 +223,7 @@ collect::Exec_status
collect::check_executable (char *target_name)
{
char target_path[MAXPATHLEN];
struct stat64 statbuf;
dbe_stat_t statbuf;
if (target_name == NULL) // not set, but assume caller knows what it's doing
return EXEC_OK;
if (getenv ("GPROFNG_SKIP_VALIDATION")) // don't check target

View File

@ -880,7 +880,7 @@ struct worker_thread_info
int thread_num; /* Application-defined thread # */
volatile int control; /* Thread state */
volatile int result; /* Return status */
struct stat64 statbuf; /* File info from stat64() */
dbe_stat_t statbuf; /* File info from stat64() */
const char *path; /* File */
};
@ -1058,9 +1058,9 @@ extract_and_save_dirname (const char *path, int status)
// get status for specified file
static int
dbe_stat_internal (const char *path, struct stat64 *sbuf, bool file_only)
dbe_stat_internal (const char *path, dbe_stat_t *sbuf, bool file_only)
{
struct stat64 statbuf;
dbe_stat_t statbuf;
int dir_status = check_dirname (path);
if (dir_status == DIR_STATUS_UNKNOWN)
{
@ -1116,7 +1116,7 @@ dbe_stat_internal (const char *path, struct stat64 *sbuf, bool file_only)
// get status for the regular file
int
dbe_stat_file (const char *path, struct stat64 *sbuf)
dbe_stat_file (const char *path, dbe_stat_t *sbuf)
{
int res = dbe_stat_internal (path, sbuf, true);
return res;
@ -1125,7 +1125,7 @@ dbe_stat_file (const char *path, struct stat64 *sbuf)
// get status for specified file
int
dbe_stat (const char *path, struct stat64 *sbuf)
dbe_stat (const char *path, dbe_stat_t *sbuf)
{
int res = dbe_stat_internal (path, sbuf, false);
return res;
@ -1159,7 +1159,7 @@ dbe_read_dir (const char *path, const char *format)
if (format_aF)
{
const char *attr = NTXT ("@"); // Link
struct stat64 sbuf;
dbe_stat_t sbuf;
sbuf.st_mode = 0;
char filename[MAXPATHLEN + 1];
snprintf (filename, sizeof (filename), NTXT ("%s/%s"), path, entry->d_name);
@ -1253,7 +1253,7 @@ dbe_delete_file (const char *pathname)
{
StringBuilder sb;
char *cmd = NULL;
struct stat64 sbuf;
dbe_stat_t sbuf;
sbuf.st_mode = 0;
int st = dbe_stat (pathname, &sbuf);
if (st == 0)

View File

@ -136,7 +136,13 @@ timestruc2hr (timestruc_t *s)
return (hrtime_t) s->tv_sec * NANOSEC + (hrtime_t) s->tv_nsec;
}
struct stat64;
#if defined(__MUSL_LIBC)
typedef struct stat dbe_stat_t;
#define fstat64 fstat
#define open64 open
#else
typedef struct stat64 dbe_stat_t;
#endif
#if defined(__cplusplus)
extern "C"
@ -162,8 +168,8 @@ extern "C"
char *get_relative_link (const char *path_to, const char *path_from);
char *get_prog_name (int basename);
char *dbe_strndup (const char *str, size_t len);
int dbe_stat (const char *path, struct stat64 *sbuf);
int dbe_stat_file (const char *path, struct stat64 *sbuf);
int dbe_stat (const char *path, dbe_stat_t *sbuf);
int dbe_stat_file (const char *path, dbe_stat_t *sbuf);
char *dbe_read_dir (const char *path, const char *format);
char *dbe_get_processes (const char *format);
char *dbe_create_directories (const char *pathname);