[PATCH] D67867: [libc] Add few docs and implementation of strcpy and strcat.

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 3 00:08:49 PDT 2019


MaskRay added a comment.

My earlier question is about why we need the namespace `__llvm_libc` at all. From `libc/src/string/strcat/strcat_test.cpp` I conclude it is for unit testing in an environment that already has a libc (gtest). This should probably be documented.

https://reviews.llvm.org/D67867#1686834 mentioned that the objcopy scheme will break the `st_size` fields of symbols.

Can we do things the other way round? No namespace, no `__llvm_libc_` prefix. Add the `-ffreestanding` compiler flag and just define `strstr, open, etc` in the global namespace. In unit tests, invoke `llvm-objcopy --redefine-syms=` to rename `strstr` to `__llvm_libc_strstr`, etc.

A `weak_alias` macro will be needed:

1. Avoid namespace pollution. ISO C interfaces should not pull in POSIX functions, e.g. `fopen` can call `strstr, strchr` (ISO C) but not `open` (POSIX). To call `open`, (a) define STV_HIDDEN `__open` (b) make `open` a weak alias of `__open` (c) call `__open` in `fopen`.
2. Weak definition for dummy implementation. Some features do not necessarily pull in functions from other components. Create a static dummy function and create a weak definition. When used as a variable, this can be used to check whether some features are unavailable.
3. Pure aliases.  Required either by standard or ABI compatibility purposes. glibc uses this a lot.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67867





More information about the llvm-commits mailing list