public inbox for libc-help@sourceware.org
 help / color / mirror / Atom feed
* [RFC PATCH v1 1/1] draft: Make non-optimized build possible
  2022-05-02 14:11 [RFC PATCH v1 0/1] Debug build? Nicholas Guriev
@ 2022-05-02 12:08 ` Nicholas Guriev
  0 siblings, 0 replies; 2+ messages in thread
From: Nicholas Guriev @ 2022-05-02 12:08 UTC (permalink / raw)
  To: libc-help

Fix compilation errors found with the -O0 flag. Autotests do not work yet.
Checked in GNU/Linux Ubuntu 21.10 with GCC 11.2.0.
---
 include/alloc_buffer.h             | 76 ++++++++++++++++--------------
 include/libc-symbols.h             |  6 +--
 include/rtld-malloc.h              |  8 ++--
 locale/programs/locfile.h          |  2 +-
 nscd/nscd-client.h                 |  2 +-
 resolv/gai_misc.c                  |  2 +-
 rt/aio_misc.c                      |  2 +-
 sysdeps/nptl/gai_misc.h            |  4 +-
 sysdeps/unix/sysv/linux/aio_misc.h |  4 +-
 9 files changed, 56 insertions(+), 50 deletions(-)

diff --git a/include/alloc_buffer.h b/include/alloc_buffer.h
index be33e8b68c..1d431d3ad4 100644
--- a/include/alloc_buffer.h
+++ b/include/alloc_buffer.h
@@ -202,44 +202,50 @@ alloc_buffer_alloc_bytes (struct alloc_buffer *buf, size_t length)
 
 /* Internal function.  Statically assert that the type size is
    constant and valid.  */
-static __always_inline size_t
-__alloc_buffer_assert_size (size_t size)
-{
-  if (!__builtin_constant_p (size))
-    {
-      __errordecl (error, "type size is not constant");
-      error ();
-    }
-  else if (size == 0)
-    {
-      __errordecl (error, "type size is zero");
-      error ();
-    }
-  return size;
-}
+//static __always_inline size_t
+//__alloc_buffer_assert_size (size_t size)
+//{
+//  if (!__builtin_constant_p (size))
+//    {
+//      __errordecl (error, "type size is not constant");
+//      error ();
+//    }
+//  else if (size == 0)
+//    {
+//      __errordecl (error, "type size is zero");
+//      error ();
+//    }
+//  return size;
+//}
+
+#define __alloc_buffer_assert_size(val) \
+  ({ _Static_assert (val > 0, "positive size"); val; })
 
 /* Internal function.  Statically assert that the type alignment is
    constant and valid.  */
-static __always_inline size_t
-__alloc_buffer_assert_align (size_t align)
-{
-  if (!__builtin_constant_p (align))
-    {
-      __errordecl (error, "type alignment is not constant");
-      error ();
-    }
-  else if (align == 0)
-    {
-      __errordecl (error, "type alignment is zero");
-      error ();
-    }
-  else if (!powerof2 (align))
-    {
-      __errordecl (error, "type alignment is not a power of two");
-      error ();
-    }
-  return align;
-}
+//static __always_inline size_t
+//__alloc_buffer_assert_align (size_t align)
+//{
+//  if (!__builtin_constant_p (align))
+//    {
+//      __errordecl (error, "type alignment is not constant");
+//      error ();
+//    }
+//  else if (align == 0)
+//    {
+//      __errordecl (error, "type alignment is zero");
+//      error ();
+//    }
+//  else if (!powerof2 (align))
+//    {
+//      __errordecl (error, "type alignment is not a power of two");
+//      error ();
+//    }
+//  return align;
+//}
+
+#define __alloc_buffer_assert_align(val) \
+  ({ _Static_assert (val > 0 && powerof2 (val), "type alignment"); val; })
 
 /* Internal function.  Obtain a pointer to an object.  */
 static inline __attribute__ ((nonnull (1))) void *
diff --git a/include/libc-symbols.h b/include/libc-symbols.h
index 662bd118b1..e5651802a6 100644
--- a/include/libc-symbols.h
+++ b/include/libc-symbols.h
@@ -71,9 +71,9 @@
 #define _LIBC	1
 
 /* Some files must be compiled with optimization on.  */
-#if !defined __ASSEMBLER__ && !defined __OPTIMIZE__
-# error "glibc cannot be compiled without optimization"
-#endif
+//#if !defined __ASSEMBLER__ && !defined __OPTIMIZE__
+//# error "glibc cannot be compiled without optimization"
+//#endif
 
 /* -ffast-math cannot be applied to the C library, as it alters the ABI.
    Some test components that use -ffast-math are currently not part of
diff --git a/include/rtld-malloc.h b/include/rtld-malloc.h
index ed70c87f40..0d7d7e7a07 100644
--- a/include/rtld-malloc.h
+++ b/include/rtld-malloc.h
@@ -38,25 +38,25 @@ extern __typeof (realloc) *__rtld_realloc attribute_hidden;
    functions.  Instead the function pointers must be used
    directly.  */
 
-__extern_inline void *
+__extern_always_inline void *
 calloc (size_t a, size_t b)
 {
   return __rtld_calloc (a, b);
 }
 
-__extern_inline void
+__extern_always_inline void
 free (void *ptr)
 {
    __rtld_free (ptr);
 }
 
-__extern_inline void *
+__extern_always_inline void *
 malloc (size_t size)
 {
   return __rtld_malloc (size);
 }
 
-__extern_inline void *
+__extern_always_inline void *
 realloc (void *ptr, size_t size)
 {
   return __rtld_realloc (ptr, size);
diff --git a/locale/programs/locfile.h b/locale/programs/locfile.h
index 57b2211e2f..894df6bbde 100644
--- a/locale/programs/locfile.h
+++ b/locale/programs/locfile.h
@@ -80,7 +80,7 @@ set_big_endian (bool big_endian)
 
 /* Munge VALUE so that, when stored, it has the correct byte order
    for the output files.  */
-static uint32_t
+static inline uint32_t
 __attribute__ ((unused))
 maybe_swap_uint32 (uint32_t value)
 {
diff --git a/nscd/nscd-client.h b/nscd/nscd-client.h
index fee2a15dcc..eaa8d7abc5 100644
--- a/nscd/nscd-client.h
+++ b/nscd/nscd-client.h
@@ -407,7 +407,7 @@ extern void __nscd_unmap (struct mapped_database *mapped)
   attribute_hidden;
 
 /* Drop reference of mapping.  */
-static int
+static inline int
 __attribute__ ((unused))
 __nscd_drop_map_ref (struct mapped_database *map, int *gc_cycle)
 {
diff --git a/resolv/gai_misc.c b/resolv/gai_misc.c
index 8ce3c778eb..2102e1797d 100644
--- a/resolv/gai_misc.c
+++ b/resolv/gai_misc.c
@@ -37,7 +37,7 @@
 #ifndef gai_create_helper_thread
 # define gai_create_helper_thread __gai_create_helper_thread
 
-extern inline int
+extern __always_inline int
 __gai_create_helper_thread (pthread_t *threadp, void *(*tf) (void *),
 			    void *arg)
 {
diff --git a/rt/aio_misc.c b/rt/aio_misc.c
index b4304d0a6f..dc18618473 100644
--- a/rt/aio_misc.c
+++ b/rt/aio_misc.c
@@ -45,7 +45,7 @@
 #ifndef aio_create_helper_thread
 # define aio_create_helper_thread __aio_create_helper_thread
 
-extern inline int
+extern __always__inline int
 __aio_create_helper_thread (pthread_t *threadp, void *(*tf) (void *), void *arg)
 {
   pthread_attr_t attr;
diff --git a/sysdeps/nptl/gai_misc.h b/sysdeps/nptl/gai_misc.h
index c09350c2ed..49beefed1c 100644
--- a/sysdeps/nptl/gai_misc.h
+++ b/sysdeps/nptl/gai_misc.h
@@ -76,7 +76,7 @@
 #define gai_start_notify_thread __gai_start_notify_thread
 #define gai_create_helper_thread __gai_create_helper_thread
 
-extern inline void
+extern __always_inline void
 __gai_start_notify_thread (void)
 {
   sigset_t ss;
@@ -86,7 +86,7 @@ __gai_start_notify_thread (void)
   assert_perror (sigerr);
 }
 
-extern inline int
+extern __always_inline int
 __gai_create_helper_thread (pthread_t *threadp, void *(*tf) (void *),
 			    void *arg)
 {
diff --git a/sysdeps/unix/sysv/linux/aio_misc.h b/sysdeps/unix/sysv/linux/aio_misc.h
index 100334ad45..aa753fbd23 100644
--- a/sysdeps/unix/sysv/linux/aio_misc.h
+++ b/sysdeps/unix/sysv/linux/aio_misc.h
@@ -25,7 +25,7 @@
 # define aio_start_notify_thread __aio_start_notify_thread
 # define aio_create_helper_thread __aio_create_helper_thread
 
-extern inline void
+extern __always_inline void
 __aio_start_notify_thread (void)
 {
   sigset_t ss;
@@ -34,7 +34,7 @@ __aio_start_notify_thread (void)
 			 __NSIG_BYTES);
 }
 
-extern inline int
+extern __always_inline int
 __aio_create_helper_thread (pthread_t *threadp, void *(*tf) (void *),
 			    void *arg)
 {
-- 
2.32.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [RFC PATCH v1 0/1] Debug build?
@ 2022-05-02 14:11 Nicholas Guriev
  2022-05-02 12:08 ` [RFC PATCH v1 1/1] draft: Make non-optimized build possible Nicholas Guriev
  0 siblings, 1 reply; 2+ messages in thread
From: Nicholas Guriev @ 2022-05-02 14:11 UTC (permalink / raw)
  To: libc-help

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 3308 bytes --]

Hello everyone!

How do I get rid of <optimized out> in GDB from glibc sources? I am used to the
-O0 compiler flag in this case, but the libc-symbols.h file blocks
non-optimized build. For what reason?

I have built glibc with CFLAGS='-ggdb3 -Og' but they still do too many
optimizations so the debugger cannot see local variables. And there is a
similar bug report in GCC, https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78685

Can we fix this on glibc side? I am attaching a work-in-progress patch that
removes an #error directive and adds some __always_inline optimizations to
strictly necessary functions. Unfortunately, I don't fully understand which
consequences it may imply.

But if glibc developers are interested, I'll be happy to putt the patch in
order.


Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7fd6b1c in elf_machine_rela (skip_ifunc=0, reloc_addr_arg=0x7ffff7fb9fe0, version=0x18, sym=0x7ffff7fb6330, reloc=0x7ffff7fb64b0, scope=0x7ffff7fbc148, map=0x7ffff7fbbdc0) at ../sysdeps/x86_64/dl-machine.h:280
(gdb) i locals
_lr = <optimized out>
_tc = 4
v = 0x0
refsym = 0x7ffff7fb6330
sym_map = <optimized out>
value = <optimized out>
reloc_addr = 0x7ffff7fb9fe0
r_type = 6
reloc_addr = <optimized out>
r_type = <optimized out>
print_err = <optimized out>
refsym = <optimized out>
sym_map = <optimized out>
value = <optimized out>
_lr = <optimized out>
_tc = <optimized out>
v = <optimized out>
strtab = <optimized out>
fmt = <optimized out>
td = <optimized out>
strtab = <optimized out>
(gdb) bt
#0  0x00007ffff7fd6b1c in elf_machine_rela (skip_ifunc=0, reloc_addr_arg=0x7ffff7fb9fe0, version=0x18, sym=0x7ffff7fb6330, reloc=0x7ffff7fb64b0, scope=0x7ffff7fbc148, map=0x7ffff7fbbdc0) at ../sysdeps/x86_64/dl-machine.h:280
#1  0x00007ffff7fd6b1c in elf_dynamic_do_Rela (skip_ifunc=<optimized out>, lazy=<optimized out>, nrelative=<optimized out>, relsize=<optimized out>, reladdr=<optimized out>, scope=<optimized out>, map=0x7ffff7fbbdc0) at /home/mymedia/код/система/glibc/elf/do-rel.h:147
#2  0x00007ffff7fd6b1c in _dl_relocate_object (l=<optimized out>, scope=<optimized out>, reloc_mode=<optimized out>, consider_profiling=<optimized out>) at dl-reloc.c:288
#3  0x00007ffff7fe8450 in dl_main (phdr=<optimized out>, phnum=<optimized out>, user_entry=<optimized out>, auxv=<optimized out>) at rtld.c:2288
#4  0x00007ffff7fe32c5 in _dl_sysdep_start (start_argptr=<optimized out>, dl_main=0x7ffff7fe60df <dl_main>) at ../sysdeps/unix/sysv/linux/dl-sysdep.c:140
#5  0x00007ffff7fe5ffe in _dl_start_final (arg=0x7fffffffd7c0) at rtld.c:510
#6  0x00007ffff7fe5ffe in _dl_start (arg=0x7fffffffd7c0) at rtld.c:597
#7  0x00007ffff7fe3bd8 in _start () from /home/mymedia/код/система/glibc/build/elf/ld.so


Nicholas Guriev (1):
  draft: Make non-optimized build possible

 include/alloc_buffer.h             | 76 ++++++++++++++++--------------
 include/libc-symbols.h             |  6 +--
 include/rtld-malloc.h              |  8 ++--
 locale/programs/locfile.h          |  2 +-
 nscd/nscd-client.h                 |  2 +-
 resolv/gai_misc.c                  |  2 +-
 rt/aio_misc.c                      |  2 +-
 sysdeps/nptl/gai_misc.h            |  4 +-
 sysdeps/unix/sysv/linux/aio_misc.h |  4 +-
 9 files changed, 56 insertions(+), 50 deletions(-)

-- 
2.32.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-05-02 14:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-02 14:11 [RFC PATCH v1 0/1] Debug build? Nicholas Guriev
2022-05-02 12:08 ` [RFC PATCH v1 1/1] draft: Make non-optimized build possible Nicholas Guriev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).