[PATCH] libc: remove/add some aliases

30 views
Skip to first unread message

Waldemar Kozaczuk

unread,
Nov 21, 2021, 3:38:15 AM11/21/21
to osv...@googlegroups.com, Waldemar Kozaczuk
This patch removes some entries from aliases.ld for symbols
that are not present in glibc shared libraries OSv dynamic linker
advertises. It also adds new entries for symbols that are present in the
same libraries.

Signed-off-by: Waldemar Kozaczuk <jwkoz...@gmail.com>
---
libc/aliases.ld | 11 ++++++-----
libc/stdio/__fprintf_chk.c | 1 -
2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/libc/aliases.ld b/libc/aliases.ld
index 14dac146..09ed4b70 100644
--- a/libc/aliases.ld
+++ b/libc/aliases.ld
@@ -29,7 +29,6 @@ __finitel = finitel;

/* locale */
__toupper_l = toupper_l;
-__setlocale = setlocale;

/* multibyte */
__mbrlen = mbrlen;
@@ -50,11 +49,7 @@ __stpncpy = stpncpy;
__strdup = strdup;
strerrordesc_np = strerror;

-/* temp */
-__mktemp = mktemp;
-
/* time */
-__clock_gettime = clock_gettime;
__gmtime_r = gmtime_r;
__strftime_l = strftime_l;

@@ -72,3 +67,9 @@ fstatat64 = fstatat;

__lseek = lseek;
__getauxval = getauxval;
+
+__getpagesize = getpagesize;
+newlocale = __newlocale;
+_exit = exit;
+_Exit = exit;
+__dn_expand = dn_expand;
diff --git a/libc/stdio/__fprintf_chk.c b/libc/stdio/__fprintf_chk.c
index 2d7e42d4..68447c63 100644
--- a/libc/stdio/__fprintf_chk.c
+++ b/libc/stdio/__fprintf_chk.c
@@ -15,4 +15,3 @@ __fprintf_chk(FILE *fp, int flag, const char *format, ...)

return ret;
}
-weak_alias(__fprintf_chk, ___fprintf_chk);
--
2.31.1

Nadav Har'El

unread,
Nov 22, 2021, 9:20:48 AM11/22/21
to Waldemar Kozaczuk, Osv Dev
On Sun, Nov 21, 2021 at 10:38 AM Waldemar Kozaczuk <jwkoz...@gmail.com> wrote:
This patch removes some entries from aliases.ld for symbols
that are not present in glibc shared libraries OSv dynamic linker
advertises. It also adds new entries for symbols that are present in the
same libraries.

Signed-off-by: Waldemar Kozaczuk <jwkoz...@gmail.com>
---
 libc/aliases.ld            | 11 ++++++-----
 libc/stdio/__fprintf_chk.c |  1 -
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/libc/aliases.ld b/libc/aliases.ld
index 14dac146..09ed4b70 100644
--- a/libc/aliases.ld
+++ b/libc/aliases.ld
@@ -29,7 +29,6 @@ __finitel = finitel;

 /* locale */
 __toupper_l = toupper_l;
-__setlocale = setlocale;

I am guessing we didn't insert those aliases for fun - I'm guessing we saw something actually using it. But if you see that this alias doesn't exist in gcc I think it's safe to remove it.


 /* multibyte */
 __mbrlen = mbrlen;
@@ -50,11 +49,7 @@ __stpncpy = stpncpy;
 __strdup = strdup;
 strerrordesc_np = strerror;

-/* temp */
-__mktemp = mktemp;
-
 /* time */
-__clock_gettime = clock_gettime;

Again, I'm guessing some old versions of libraries or something used these aliases,
because a Google search for __clock_gettime returns stuff.
I'm fine with removing those aliases if they aren't used in modern code.
 
 __gmtime_r = gmtime_r;
 __strftime_l = strftime_l;

@@ -72,3 +67,9 @@ fstatat64 = fstatat;

 __lseek = lseek;
 __getauxval = getauxval;
+
+__getpagesize = getpagesize;

We already have such an alias in runtime.cc, so please remove it from there to add it here.
 
+newlocale = __newlocale;

We already have such an alias in runtime.cc, so please remove it from there to add it here.

+_exit = exit;
+_Exit = exit;

Again, we already had those aliases, in runtime.cc.
Please remove the aliases from there, and also copy the comment to aliases.ld.

After you remove all the ALIAS calls from runtime.cc you can remove the definition of ALIAS :-)
 
+__dn_expand = dn_expand;
diff --git a/libc/stdio/__fprintf_chk.c b/libc/stdio/__fprintf_chk.c
index 2d7e42d4..68447c63 100644
--- a/libc/stdio/__fprintf_chk.c
+++ b/libc/stdio/__fprintf_chk.c
@@ -15,4 +15,3 @@ __fprintf_chk(FILE *fp, int flag, const char *format, ...)

     return ret;
 }
-weak_alias(__fprintf_chk, ___fprintf_chk);
--
2.31.1

--
You received this message because you are subscribed to the Google Groups "OSv Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to osv-dev+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/osv-dev/20211121083757.22214-1-jwkozaczuk%40gmail.com.

Waldek Kozaczuk

unread,
Nov 25, 2021, 7:38:42 AM11/25/21
to OSv Development
On Monday, November 22, 2021 at 9:20:48 AM UTC-5 Nadav Har'El wrote:
On Sun, Nov 21, 2021 at 10:38 AM Waldemar Kozaczuk <jwkoz...@gmail.com> wrote:
This patch removes some entries from aliases.ld for symbols
that are not present in glibc shared libraries OSv dynamic linker
advertises. It also adds new entries for symbols that are present in the
same libraries.

Signed-off-by: Waldemar Kozaczuk <jwkoz...@gmail.com>
---
 libc/aliases.ld            | 11 ++++++-----
 libc/stdio/__fprintf_chk.c |  1 -
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/libc/aliases.ld b/libc/aliases.ld
index 14dac146..09ed4b70 100644
--- a/libc/aliases.ld
+++ b/libc/aliases.ld
@@ -29,7 +29,6 @@ __finitel = finitel;

 /* locale */
 __toupper_l = toupper_l;
-__setlocale = setlocale;

I am guessing we didn't insert those aliases for fun - I'm guessing we saw something actually using it. But if you see that this alias doesn't exist in gcc I think it's safe to remove it.

Yeah, I was the one that populated this file mostly as part of the effort when migrating to the newer musl 1.1.24. And I may have done some things wrong. I justify the removal of some of those aliases on the fact tha tI could not find the __setlocale in any shared libraries advertised by core/elf.cc. I also could not find __setlocale in any header files on the host. But maybe I should crosscheck Ubuntu.


 /* multibyte */
 __mbrlen = mbrlen;
@@ -50,11 +49,7 @@ __stpncpy = stpncpy;
 __strdup = strdup;
 strerrordesc_np = strerror;

-/* temp */
-__mktemp = mktemp;
-
 /* time */
-__clock_gettime = clock_gettime;

Again, I'm guessing some old versions of libraries or something used these aliases,
because a Google search for __clock_gettime returns stuff.
I'm fine with removing those aliases if they aren't used in modern code.
I think it is BSD/MacOS-ism. I could not find it the Linux host shared libraries nor headers.
 
 __gmtime_r = gmtime_r;
 __strftime_l = strftime_l;

@@ -72,3 +67,9 @@ fstatat64 = fstatat;

 __lseek = lseek;
 __getauxval = getauxval;
+
+__getpagesize = getpagesize;

We already have such an alias in runtime.cc, so please remove it from there to add it here.
Sure. 
 
+newlocale = __newlocale;

We already have such an alias in runtime.cc, so please remove it from there to add it here.
Sure. 

Waldemar Kozaczuk

unread,
Nov 26, 2021, 3:53:03 PM11/26/21
to osv...@googlegroups.com, Waldemar Kozaczuk
This patch removes 3 aliases from aliases.ld for symbols that are either
internal musl symbols or are no longer present in glibc shared libraries
OSv dynamic linker advertises.

It also adds new entries for symbols that are present in the same libraries
and removed corresponding __attribute__(alias) statements from
runtime.cc.

Finally we also remove obsolete ___fprintf_chk alias.

Signed-off-by: Waldemar Kozaczuk <jwkoz...@gmail.com>
---
libc/aliases.ld | 11 ++++++-----
libc/stdio/__fprintf_chk.c | 1 -
runtime.cc | 10 ----------
3 files changed, 6 insertions(+), 16 deletions(-)

diff --git a/libc/aliases.ld b/libc/aliases.ld
index 14dac146..09ed4b70 100644
--- a/libc/aliases.ld
+++ b/libc/aliases.ld
@@ -29,7 +29,6 @@ __finitel = finitel;

/* locale */
__toupper_l = toupper_l;
-__setlocale = setlocale;

/* multibyte */
__mbrlen = mbrlen;
@@ -50,11 +49,7 @@ __stpncpy = stpncpy;
__strdup = strdup;
strerrordesc_np = strerror;

-/* temp */
-__mktemp = mktemp;
-
/* time */
-__clock_gettime = clock_gettime;
__gmtime_r = gmtime_r;
__strftime_l = strftime_l;

@@ -72,3 +67,9 @@ fstatat64 = fstatat;

__lseek = lseek;
__getauxval = getauxval;
+
+__getpagesize = getpagesize;
+newlocale = __newlocale;
+_exit = exit;
+_Exit = exit;
+__dn_expand = dn_expand;
diff --git a/libc/stdio/__fprintf_chk.c b/libc/stdio/__fprintf_chk.c
index 2d7e42d4..68447c63 100644
--- a/libc/stdio/__fprintf_chk.c
+++ b/libc/stdio/__fprintf_chk.c
@@ -15,4 +15,3 @@ __fprintf_chk(FILE *fp, int flag, const char *format, ...)

return ret;
}
-weak_alias(__fprintf_chk, ___fprintf_chk);
diff --git a/runtime.cc b/runtime.cc
index 3335552d..6a51583e 100644
--- a/runtime.cc
+++ b/runtime.cc
@@ -71,10 +71,6 @@

#define __LC_LAST 13

-#define __ALIAS(old, new) \
- __typeof(old) new __attribute__((alias(#old)))
-#define ALIAS(old, new) extern "C" __ALIAS(old, new)
-
void *__dso_handle;

static void print_backtrace(void)
@@ -198,7 +194,6 @@ int getpagesize()
{
return 4096;
}
-ALIAS(getpagesize, __getpagesize);

int vfork()
{
@@ -346,8 +341,6 @@ __locale_t __newlocale(int category_mask, const char *locale, locale_t base)
return nullptr;
}

-ALIAS(__newlocale, newlocale);
-
long sysconf(int name)
{
switch (name) {
@@ -423,9 +416,6 @@ void exit(int status)
// "The function _exit() is like exit(3), but does not call any functions
// registered with atexit(3) or on_exit(3)."
//
-// Since we do nothing for those anyway, they are equal.
-ALIAS(exit, _exit);
-ALIAS(exit, _Exit);

int atexit(void (*func)())
{
--
2.31.1

Waldemar Kozaczuk

unread,
Nov 26, 2021, 3:53:05 PM11/26/21
to osv...@googlegroups.com, Waldemar Kozaczuk
This patch is the first one in the series that annotates relevant
symbols across number of source files in order to expose or hide them
when kernel is compiled to hide non-glibc symbols. Please note that none
of this patches neither hides nor exposes any symbols. In essense it will
only have an effect once we make changes to the makefile to allow compiling
the kernel with most symbols hidden.

This patch adds new header - export.h - with new macros that either
expose (__visibility__("default")) or hide (__visibility__("hidden"))
the symbols. Please read the comments in the header file for more
details.

Signed-off-by: Waldemar Kozaczuk <jwkoz...@gmail.com>
---
include/osv/export.h | 41 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
create mode 100644 include/osv/export.h

diff --git a/include/osv/export.h b/include/osv/export.h
new file mode 100644
index 00000000..605e8e10
--- /dev/null
+++ b/include/osv/export.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2021 Waldemar Kozaczuk
+ *
+ * This work is open source software, licensed under the terms of the
+ * BSD license as described in the LICENSE file in the top-level directory.
+ */
+
+#ifndef EXPORT_H
+#define EXPORT_H
+
+//
+// Please note that the macros below are used in the source files and
+// are intended to expose the annotated symbols as public when the kernel
+// files are compiled with the flag '-fvisibility=hidden'. When the kernel
+// is compiled without visibility flag, these macro do not have any affect
+// as all symbols in this case are exposed as public. So either way, the symbols
+// annotated with these macros yield desired effect.
+// We do not really need to define a macro for each Linux glibc library and we could
+// have had single OSV_GLIBC_API macro instead of eight ones below. However by
+// having a macro for each shared library file where a symbol is part of,
+// we automatically self-document the code and in future could auto-generate some
+// docs.
+// More specifically, as an example, if given symbol is annotated with OSV_LIBC_API, it means
+// that it physically part of the libc.so.6 file on Linux, etc.
+#define OSV_LIBAIO_API __attribute__((__visibility__("default")))
+#define OSV_LIBC_API __attribute__((__visibility__("default")))
+#define OSV_LIBM_API __attribute__((__visibility__("default")))
+#define OSV_LIBBSD_API __attribute__((__visibility__("default")))
+#define OSV_LIBPTHREAD_API __attribute__((__visibility__("default")))
+#define OSV_LIBUTIL_API __attribute__((__visibility__("default")))
+#define OSV_LIBXENSTORE_API __attribute__((__visibility__("default")))
+#define OSV_LD_LINUX_x86_64_API __attribute__((__visibility__("default")))
+
+// In some very few cases, when source files are compiled without visibility
+// flag in order to expose most symbols in the corresponding file, there are some specific
+// symbols in the same file that we want to hide and this is where we use this macro.
+// Regardless if we hide most symbols in the kernel or not, the annotated symbols would
+// be always hidden.
+#define OSV_HIDDEN __attribute__((__visibility__("hidden")))
+
+#endif /* EXPORT_H */
--
2.31.1

Nadav Har'El

unread,
Nov 28, 2021, 5:24:24 AM11/28/21
to Waldemar Kozaczuk, Osv Dev
Looks good, but I have just one trivial comment below.

I suggest moving the comment we had on _exit here, and not just dropping it. On Linux, _exit() is *not* the same as exit(), and if on OSv it's just an alias, I think we need a comment to explain why.
 
--
You received this message because you are subscribed to the Google Groups "OSv Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to osv-dev+u...@googlegroups.com.

Commit Bot

unread,
Nov 28, 2021, 7:46:03 AM11/28/21
to osv...@googlegroups.com, Waldemar Kozaczuk
From: Waldemar Kozaczuk <jwkoz...@gmail.com>
Committer: Waldemar Kozaczuk <jwkoz...@gmail.com>
Branch: master

libc: remove/add some aliases

This patch removes 3 aliases from aliases.ld for symbols that are either
internal musl symbols or are no longer present in glibc shared libraries
OSv dynamic linker advertises.

It also adds new entries for symbols that are present in the same libraries
and removed corresponding __attribute__(alias) statements from
runtime.cc.

Finally we also remove obsolete ___fprintf_chk alias.

Signed-off-by: Waldemar Kozaczuk <jwkoz...@gmail.com>

---
diff --git a/libc/aliases.ld b/libc/aliases.ld
--- a/libc/aliases.ld
+++ b/libc/aliases.ld
@@ -29,7 +29,7 @@ __finitel = finitel;

/* locale */
__toupper_l = toupper_l;
-__setlocale = setlocale;
+newlocale = __newlocale;

/* multibyte */
__mbrlen = mbrlen;
@@ -50,11 +50,7 @@ __stpncpy = stpncpy;
__strdup = strdup;
strerrordesc_np = strerror;

-/* temp */
-__mktemp = mktemp;
-
/* time */
-__clock_gettime = clock_gettime;
__gmtime_r = gmtime_r;
__strftime_l = strftime_l;

@@ -69,6 +65,13 @@ stat64 = stat;
fstat64 = fstat;
lstat64 = lstat;
fstatat64 = fstatat;
-
__lseek = lseek;
+
__getauxval = getauxval;
+__getpagesize = getpagesize;
+
+/* Since we do nothing for those anyway, they are equal. */
+_exit = exit;
+_Exit = exit;
+
+__dn_expand = dn_expand;
diff --git a/libc/stdio/__fprintf_chk.c b/libc/stdio/__fprintf_chk.c
--- a/libc/stdio/__fprintf_chk.c
+++ b/libc/stdio/__fprintf_chk.c
@@ -15,4 +15,3 @@ __fprintf_chk(FILE *fp, int flag, const char *format, ...)

return ret;
}
-weak_alias(__fprintf_chk, ___fprintf_chk);
diff --git a/runtime.cc b/runtime.cc

Commit Bot

unread,
Nov 28, 2021, 7:46:05 AM11/28/21
to osv...@googlegroups.com, Waldemar Kozaczuk
From: Waldemar Kozaczuk <jwkoz...@gmail.com>
Committer: Waldemar Kozaczuk <jwkoz...@gmail.com>
Branch: master

prepare to hide kernel symbols: add macros to expose and hide symbols

This patch is the first one in the series that annotates relevant
symbols across number of source files in order to expose or hide them
when kernel is compiled to hide non-glibc symbols. Please note that none
of this patches neither hides nor exposes any symbols. In essense it will
only have an effect once we make changes to the makefile to allow compiling
the kernel with most symbols hidden.

This patch adds new header - export.h - with new macros that either
expose (__visibility__("default")) or hide (__visibility__("hidden"))
the symbols. Please read the comments in the header file for more
details.

Signed-off-by: Waldemar Kozaczuk <jwkoz...@gmail.com>

---
diff --git a/include/osv/export.h b/include/osv/export.h
--- a/include/osv/export.h
Reply all
Reply to author
Forward
0 new messages