From 35ef7358fdb68d487be174c66b21cbc6bfa03328 Mon Sep 17 00:00:00 2001 From: "Wiktor S. Ovalle Correa" Date: Fri, 14 May 2021 12:24:40 +0200 Subject: [PATCH] [EGD-6035] Fix iosyscalls build on GLIBC_2.33 Newer versions of glibc have stat symbols family incompatible with earlier versions. --- .../libiosyscalls/src/syscalls_posix.cpp | 179 ++++++++++++------ board/linux/libiosyscalls/version.txt | 13 +- 2 files changed, 133 insertions(+), 59 deletions(-) diff --git a/board/linux/libiosyscalls/src/syscalls_posix.cpp b/board/linux/libiosyscalls/src/syscalls_posix.cpp index ef75f9771276aa34088e8182399b29fe6710996e..7d457eb0fd6be3d4a2882443549e9b20eb53cded 100644 --- a/board/linux/libiosyscalls/src/syscalls_posix.cpp +++ b/board/linux/libiosyscalls/src/syscalls_posix.cpp @@ -48,6 +48,15 @@ namespace __REAL_DECL(fsync); __REAL_DECL(fdatasync); +#if __GLIBC__ > 2 || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 32)) + __REAL_DECL(stat); + __REAL_DECL(lstat); + __REAL_DECL(fstat); + + __REAL_DECL(stat64); + __REAL_DECL(lstat64); + __REAL_DECL(fstat64); +#else __REAL_DECL(__xstat); __REAL_DECL(__lxstat); __REAL_DECL(__fxstat); @@ -55,7 +64,7 @@ namespace __REAL_DECL(__xstat64); __REAL_DECL(__lxstat64); __REAL_DECL(__fxstat64); - +#endif __REAL_DECL(read); __REAL_DECL(write); __REAL_DECL(lseek); @@ -92,6 +101,15 @@ namespace __REAL_DLSYM(fsync); __REAL_DLSYM(fdatasync); +#if __GLIBC__ > 2 || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 32)) + __REAL_DLSYM(stat); + __REAL_DLSYM(lstat); + __REAL_DLSYM(fstat); + + __REAL_DLSYM(stat64); + __REAL_DLSYM(lstat64); + __REAL_DLSYM(fstat64); +#else __REAL_DLSYM(__xstat); __REAL_DLSYM(__lxstat); __REAL_DLSYM(__fxstat); @@ -99,7 +117,7 @@ namespace __REAL_DLSYM(__xstat64); __REAL_DLSYM(__lxstat64); __REAL_DLSYM(__fxstat64); - +#endif __REAL_DLSYM(read); __REAL_DLSYM(write); __REAL_DLSYM(lseek); @@ -114,11 +132,16 @@ namespace if (!(real::link && real::unlink && real::symlink && real::fcntl && real::chdir && real::fchdir && real::getcwd && real::getwd && real::get_current_dir_name && real::mkdir && real::chmod && real::fchmod && - real::fsync && real::fdatasync && real::__xstat && real::__lxstat && real::__fxstat && real::__xstat64 && - real::__lxstat64 && real::__fxstat64 && real::read && real::write && real::lseek && real::lseek64 && + real::fsync && real::fdatasync && real::read && real::write && real::lseek && real::lseek64 && real::mount && real::umount && real::ioctl && real::poll && real::statvfs #if __GLIBC__ > 2 || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 28)) && real::fcntl64 +#endif +#if __GLIBC__ > 2 || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 32)) + && real::stat && real::lstat && real::fstat && real::stat64 && real::lstat64 && real::fstat64 +#else + && real::__xstat && real::__lxstat && real::__fxstat && real::__xstat64 && real::__lxstat64 && + real::__fxstat64 #endif )) { abort(); @@ -263,49 +286,6 @@ extern "C" } __asm__(".symver _iosys_unlink,unlink@GLIBC_2.2.5"); - int _iosys_stat(const char *file, struct stat *pstat) - { - if (vfs::redirect_to_image(file)) { - TRACE_SYSCALLN("(%s) -> VFS", file); - return vfs::invoke_fs(&fs::stat, file, *pstat); - } - else { - TRACE_SYSCALLN("(%s) -> linux fs", file); - char tmp[PATH_MAX]; - const auto newfile = vfs::npath_translate(file, tmp); - return real::__xstat(1, newfile, pstat); - } - } - __asm__(".symver _iosys_stat,stat@GLIBC_2.2.5"); - - int _iosys_lstat(const char *pathname, struct stat *statbuf) - { - if (vfs::redirect_to_image(pathname)) { - TRACE_SYSCALLN("(%s) -> VFS", pathname); - return vfs::invoke_fs(&fs::stat, pathname, *statbuf); - } - else { - TRACE_SYSCALLN("(%s) -> linux fs", pathname); - char tmp[PATH_MAX]; - const auto newpath = vfs::npath_translate(pathname, tmp); - return real::__lxstat(1, newpath, statbuf); - } - } - __asm__(".symver _iosys_lstat,lstat@GLIBC_2.2.5"); - - int _iosys_fstat(int fd, struct stat *pstat) - { - if (vfs::is_image_fd(fd)) { - TRACE_SYSCALLN("(%d) -> VFS", fd); - return vfs::invoke_fs(&fs::fstat, vfs::to_image_fd(fd), *pstat); - } - else { - TRACE_SYSCALLN("(%d) -> linux fs", fd); - return real::__fxstat(1, fd, pstat); - } - } - __asm__(".symver _iosys_fstat,fstat@GLIBC_2.2.5"); - int _iosys_fcntl(int fd, int cmd, ... /* arg */) { if (vfs::is_image_fd(fd)) { @@ -527,6 +507,94 @@ extern "C" } __asm__(".symver _iosys_symlink,symlink@GLIBC_2.2.5"); +#if __GLIBC__ > 2 || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 32)) + int _iosys_stat(const char *file, struct stat *pstat) + { + if (vfs::redirect_to_image(file)) { + TRACE_SYSCALLN("(%s) -> VFS", file); + return vfs::invoke_fs(&fs::stat, file, *pstat); + } + else { + TRACE_SYSCALLN("(%s) -> linux fs", file); + char tmp[PATH_MAX]; + const auto newfile = vfs::npath_translate(file, tmp); + return real::stat(newfile, pstat); + } + } + __asm__(".symver _iosys_stat,stat@GLIBC_2.33"); + + int _iosys_lstat(const char *pathname, struct stat *statbuf) + { + if (vfs::redirect_to_image(pathname)) { + TRACE_SYSCALLN("(%s) -> VFS", pathname); + return vfs::invoke_fs(&fs::stat, pathname, *statbuf); + } + else { + TRACE_SYSCALLN("(%s) -> linux fs", pathname); + char tmp[PATH_MAX]; + const auto newpath = vfs::npath_translate(pathname, tmp); + return real::lstat(newpath, statbuf); + } + } + __asm__(".symver _iosys_lstat,lstat@GLIBC_2.33"); + + int _iosys_fstat(int fd, struct stat *pstat) + { + if (vfs::is_image_fd(fd)) { + TRACE_SYSCALLN("(%d) -> VFS", fd); + return vfs::invoke_fs(&fs::fstat, vfs::to_image_fd(fd), *pstat); + } + else { + TRACE_SYSCALLN("(%d) -> linux fs", fd); + return real::fstat(fd, pstat); + } + } + __asm__(".symver _iosys_fstat,fstat@GLIBC_2.33"); + + int _iosys_stat64(const char *file, struct stat64 *pstat) + { + if (vfs::redirect_to_image(file)) { + TRACE_SYSCALLN("(%s) -> VFS", file); + return stat(file, (struct stat *)pstat); + } + else { + TRACE_SYSCALLN("(%s) -> linux fs", file); + char tmp[PATH_MAX]; + const auto newfile = vfs::npath_translate(file, tmp); + return real::stat64(newfile, pstat); + } + } + __asm__(".symver _iosys_stat64,stat64@GLIBC_2.33"); + + int _iosys_lstat64(const char *pathname, struct stat64 *statbuf) + { + if (vfs::redirect_to_image(pathname)) { + TRACE_SYSCALLN("(%s) -> VFS", pathname); + return lstat(pathname, (struct stat *)statbuf); + } + else { + TRACE_SYSCALLN("(%s) -> linux fs", pathname); + char tmp[PATH_MAX]; + const auto newpath = vfs::npath_translate(pathname, tmp); + return real::lstat64(newpath, statbuf); + } + } + __asm__(".symver _iosys_lstat64,lstat64@GLIBC_2.33"); + + int _iosys_fstat64(int fd, struct stat64 *pstat) + { + if (vfs::is_image_fd(fd)) { + TRACE_SYSCALLN("(%d) -> VFS", fd); + return fstat(fd, (struct stat *)pstat); + } + else { + TRACE_SYSCALLN("(%d) -> linux fs", fd); + return real::fstat64(fd, pstat); + } + } + __asm__(".symver _iosys_fstat64,fstat64@GLIBC_2.33"); + +#else int _iosys_xstat(int ver, const char *path, struct stat *stat_buf) { if (vfs::redirect_to_image(path)) { @@ -570,14 +638,6 @@ extern "C" } __asm__(".symver _iosys_fxstat,__fxstat@GLIBC_2.2.5"); - int _iosys_fxstatat(int vers, int fd, const char *filename, struct stat *buf, int flag) - { - errno = ENOSYS; - std::cerr << "Unsupported syscall " << __PRETTY_FUNCTION__ << std::endl; - return -1; - } - __asm__(".symver _iosys_fxstatat,__fxstatat@GLIBC_2.4"); - int _iosys_xstat64(int ver, const char *path, struct stat64 *stat_buf) { if (vfs::redirect_to_image(path)) { @@ -620,6 +680,15 @@ extern "C" } } __asm__(".symver _iosys_fxstat64,__fxstat64@GLIBC_2.2.5"); +#endif + + int _iosys_fxstatat(int vers, int fd, const char *filename, struct stat *buf, int flag) + { + errno = ENOSYS; + std::cerr << "Unsupported syscall " << __PRETTY_FUNCTION__ << std::endl; + return -1; + } + __asm__(".symver _iosys_fxstatat,__fxstatat@GLIBC_2.4"); int _iosys_fxstatat64(int vers, int fd, const char *filename, struct stat64 *buf, int flag) { diff --git a/board/linux/libiosyscalls/version.txt b/board/linux/libiosyscalls/version.txt index a8d1a66560afa3b93da8fded6ef10959066cda40..71cb276b2a3e74fb9513d6f0712274ea6e116db7 100644 --- a/board/linux/libiosyscalls/version.txt +++ b/board/linux/libiosyscalls/version.txt @@ -40,9 +40,6 @@ GLIBC_2.2.5 { # posix link; unlink; - stat; - lstat; - fstat; fcntl; fcntl64; chdir; @@ -71,7 +68,6 @@ GLIBC_2.2.5 { mount; umount; statvfs; - # posix - dirent opendir; closedir; @@ -89,3 +85,12 @@ GLIBC_2.4 { __fxstatat; __fxstatat64; }; +GLIBC_2.33 { + global: + stat; + lstat; + fstat; + stat64; + lstat64; + fstat64; +};