[libc-commits] [PATCH] D94195: [libc] Switch to use a macro which does not insert a section for every libc function.

Siva Chandra via Phabricator via libc-commits libc-commits at lists.llvm.org
Thu Jan 7 16:36:40 PST 2021


sivachandra added inline comments.


================
Comment at: libc/src/__support/common.h.def:20
+#define LLVM_LIBC_FUNCTION(type, name, arglist) \
+  type name arglist; \
+  decltype(name) __##name##_impl__ __asm__(#name); \
----------------
mcgrathr wrote:
> michaelrj wrote:
> > mcgrathr wrote:
> > > I'd argue for leaving this decl out just to enforce that you only use this when you've included the public API header that declares the public name.
> > We don't always include the corresponding `.h` file so we don't always have the namespace-scoped name available to use with decltype. That is why I have added this declaration.
> It is dangerously wrong to define the public API function without its public API declaration in scope.
> 
By public API function, do you mean the declaration of say `strlen` from the public `string.h` header file?
The declaration here is not declaring the public function from `string.h`. This macro will be used within the  namespace `__llvm_libc` so it is declaring the internal function here.

```
namespace __llvm_libc {
LLVM_LIBC_FUNCTION(size_t, strlen, (...)) {
  ...
}
} // namespace __llvm_libc
```

If we want to avoid such a declaration, we have to include the corresponding internal header (for example, `src/string/strlen.h`) which we don't do with all functions.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94195/new/

https://reviews.llvm.org/D94195



More information about the libc-commits mailing list