public inbox for libc-help@sourceware.org
 help / color / mirror / Atom feed
From: "Dmitrowski, Lukasz" <extern.Lukasz.Dmitrowski@elektrobit.com>
To: "libc-help@sourceware.org" <libc-help@sourceware.org>
Subject: Bulding syscall wrapper: how glibc determines if assembly or macro wrapper will generated?
Date: Mon, 19 Jul 2021 09:26:39 +0000	[thread overview]
Message-ID: <AM9P195MB13001B71890B58DB18745582A1E19@AM9P195MB1300.EURP195.PROD.OUTLOOK.COM> (raw)

Hello,

I create a documentation describing how glibc builds syscall wrappers. I am currently limited to Linux x86_64 architecture only and base on https://sourceware.org/glibc/wiki/SyscallWrappers + source code analysis.

I want to to know how glibc build system decides what type of syscall wrapper will be generated, assembly wrapper or macro wrapper. I have troubles trying to figure out how the glibc build system works on this level.

1. make-syscall.sh produces sysd-syscalls, that contains build formulas for assembly wrappers.
How sysd-syscalls is used by the build system after it is generated?

2. I found out that if sysd-syscalls contains a build formula for assembly wrapper then this formula is always used when building glibc, but in some cases sysd-syscalls also shows that a *.c wrapper exists, even that it contains assembly wrapper formula. This is because make-syscall.sh searches multiple syscalls.list files and multiple related sysdirs for *.c wrappers, so sometimes *.c wrapper exists in such relation and sometimes not. Both are included into sysd-syscalls.

Example:
#### DIRECTORY = sysdeps/unix/sysv/linux/x86_64
#### SYSDIRS = sysdeps/unix/sysv/linux/x86_64/64
...
#### CALL=socket NUMBER=41 ARGS=i:iii SOURCE=-
ifeq (,$(filter socket,$(unix-syscalls)))
unix-syscalls += socket
$(foreach p,$(sysd-rules-targets),$(foreach o,$(object-suffixes),$(objpfx)$(patsubst %,$p,socket)$o)): \
                $(..)sysdeps/unix/make-syscalls.sh
        $(make-target-directory)
        (echo '#define SYSCALL_NAME socket'; \
         echo '#define SYSCALL_NARGS 3'; \
         echo '#define SYSCALL_SYMBOL __socket'; \
         echo '#define SYSCALL_CANCELLABLE 0'; \
         echo '#define SYSCALL_NOERRNO 0'; \
         echo '#define SYSCALL_ERRVAL 0'; \
         echo '#include <syscall-template.S>'; \
         echo 'weak_alias (__socket, socket)'; \
         echo 'hidden_weak (socket)'; \
        ) | $(compile-syscall) $(foreach p,$(patsubst %socket,%,$(basename $(@F))),$($(p)CPPFLAGS))
endif

...

#### DIRECTORY = sysdeps/unix
#### SYSDIRS = sysdeps/unix/sysv/linux/x86_64/64 sysdeps/unix/sysv/linux/x86_64 sysdeps/unix/sysv/linux/x86 sysdeps/x86/nptl sysdeps/unix/sysv/linux/wordsize-64 sysdeps/x86_64/nptl sysdeps/unix/sysv/linux sysdeps/nptl sysdeps/pthread sysdeps/gnu sysdeps/unix/inet sysdeps/unix/sysv sysdeps/unix/x86_64
...
#### CALL=socket NUMBER=41 ARGS=i:iii SOURCE=sysdeps/unix/sysv/linux/socket.c

--
Where is the exact point in the build system that decides if assembly wrapper (from template-syscall.S) or macro wrapper (from *.c file) will be generated?

3. If syscall wrapper is generated from *.c file, where can I find how the build formula is prepared by the build system?

4. How glibc determines a set of directories where make-syscall.sh looks for syscalls.list and *.c syscall wrappers? ($thisdir and $sysdirs variables in make-syscalls.sh)

Will be greateful for help or reference to some docs. Thank you in advance!


             reply	other threads:[~2021-07-19  9:26 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-19  9:26 Dmitrowski, Lukasz [this message]
2021-07-19 12:51 ` Adhemerval Zanella

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AM9P195MB13001B71890B58DB18745582A1E19@AM9P195MB1300.EURP195.PROD.OUTLOOK.COM \
    --to=extern.lukasz.dmitrowski@elektrobit.com \
    --cc=libc-help@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).