diff mbox series

tools/mm: fix undefined reference to pthread_once

Message ID 20230725092149.443119-1-xiexiuqi@huawei.com (mailing list archive)
State New
Headers show
Series tools/mm: fix undefined reference to pthread_once | expand

Commit Message

Xie XiuQi July 25, 2023, 9:21 a.m. UTC
Commit 97d5f2e9ee12 ("tools api fs: More thread safety for global
filesystem variables") introduces pthread_once, so the libpthread
should be added at link time, or we'll meet the following compile
error when 'make -C tools/mm':

  gcc -Wall -Wextra -I../lib/ -o page-types page-types.c ../lib/api/libapi.a
  ~/linux/tools/lib/api/fs/fs.c:146: undefined reference to `pthread_once'
  ~/linux/tools/lib/api/fs/fs.c:147: undefined reference to `pthread_once'
  ~/linux/tools/lib/api/fs/fs.c:148: undefined reference to `pthread_once'
  ~/linux/tools/lib/api/fs/fs.c:149: undefined reference to `pthread_once'
  ~/linux/tools/lib/api/fs/fs.c:150: undefined reference to `pthread_once'
  /usr/bin/ld: ../lib/api/libapi.a(libapi-in.o):~/linux/tools/lib/api/fs/fs.c:151:
  more undefined references to `pthread_once' follow
  collect2: error: ld returned 1 exit status
  make: *** [Makefile:22: page-types] Error 1

Fixes: 97d5f2e9ee12 ("tools api fs: More thread safety for global filesystem variables")
Signed-off-by: Xie XiuQi <xiexiuqi@huawei.com>
---
 tools/mm/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Ian Rogers July 26, 2023, 5:26 p.m. UTC | #1
On Tue, Jul 25, 2023 at 2:24 AM Xie XiuQi <xiexiuqi@huawei.com> wrote:
>
> Commit 97d5f2e9ee12 ("tools api fs: More thread safety for global
> filesystem variables") introduces pthread_once, so the libpthread
> should be added at link time, or we'll meet the following compile
> error when 'make -C tools/mm':
>
>   gcc -Wall -Wextra -I../lib/ -o page-types page-types.c ../lib/api/libapi.a
>   ~/linux/tools/lib/api/fs/fs.c:146: undefined reference to `pthread_once'
>   ~/linux/tools/lib/api/fs/fs.c:147: undefined reference to `pthread_once'
>   ~/linux/tools/lib/api/fs/fs.c:148: undefined reference to `pthread_once'
>   ~/linux/tools/lib/api/fs/fs.c:149: undefined reference to `pthread_once'
>   ~/linux/tools/lib/api/fs/fs.c:150: undefined reference to `pthread_once'
>   /usr/bin/ld: ../lib/api/libapi.a(libapi-in.o):~/linux/tools/lib/api/fs/fs.c:151:
>   more undefined references to `pthread_once' follow
>   collect2: error: ld returned 1 exit status
>   make: *** [Makefile:22: page-types] Error 1
>
> Fixes: 97d5f2e9ee12 ("tools api fs: More thread safety for global filesystem variables")
> Signed-off-by: Xie XiuQi <xiexiuqi@huawei.com>

Apologies.
Acked-by: Ian Rogers <irogers@google.com>

Alternatively we could #ifdef the behavior, but this way is cleaner imo.

Thanks,
Ian

> ---
>  tools/mm/Makefile | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/mm/Makefile b/tools/mm/Makefile
> index 6c1da51f4177..9997b2e401ae 100644
> --- a/tools/mm/Makefile
> +++ b/tools/mm/Makefile
> @@ -9,7 +9,7 @@ LIB_DIR = ../lib/api
>  LIBS = $(LIB_DIR)/libapi.a
>
>  CFLAGS += -Wall -Wextra -I../lib/
> -LDFLAGS += $(LIBS)
> +LDFLAGS += $(LIBS) -lpthread
>
>  all: $(TARGETS)
>
> --
> 2.25.1
>
diff mbox series

Patch

diff --git a/tools/mm/Makefile b/tools/mm/Makefile
index 6c1da51f4177..9997b2e401ae 100644
--- a/tools/mm/Makefile
+++ b/tools/mm/Makefile
@@ -9,7 +9,7 @@  LIB_DIR = ../lib/api
 LIBS = $(LIB_DIR)/libapi.a
 
 CFLAGS += -Wall -Wextra -I../lib/
-LDFLAGS += $(LIBS)
+LDFLAGS += $(LIBS) -lpthread
 
 all: $(TARGETS)