Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools/elfutils: do not link gnulib to libelf #15368

Merged
merged 4 commits into from
May 31, 2024

Conversation

mpratt14
Copy link
Contributor

@mpratt14 mpratt14 commented May 2, 2024

ping @robimarko @httpstorm @trippleflux

This is the direct/general way to stop extra symbols from being in libelf
(I also noticed that we weren't installing any binaries and found the reason for that, so lets just install the unique ones)

This is purposefully not rebased on top so that it can be shown that it also fixes openwrt/packages#24030
alongside with #15337 which just removes the actual extra definition in that specific case

Of course, this needs testing on macOS, as I have a feeling there is some other reason that they were linked together
that I just can't see because it only applies to macOS...

@github-actions github-actions bot added the build/scripts/tools pull request/issues for build, scripts and tools related changes label May 2, 2024
@trippleflux
Copy link

Getting :

  CC      /home/username/works/openwrt/build_dir/target-x86_64_glibc_custom/linux-x86_64/linux-6.6.30/tools/objtool/objtool.o
  CC      /home/username/works/openwrt/build_dir/target-x86_64_glibc_custom/linux-x86_64/linux-6.6.30/tools/objtool/orc_gen.o
  CC      /home/username/works/openwrt/build_dir/target-x86_64_glibc_custom/linux-x86_64/linux-6.6.30/tools/objtool/arch/x86/decode.o
  CC      /home/username/works/openwrt/build_dir/target-x86_64_glibc_custom/linux-x86_64/linux-6.6.30/tools/objtool/orc_dump.o
  CC      /home/username/works/openwrt/build_dir/target-x86_64_glibc_custom/linux-x86_64/linux-6.6.30/tools/objtool/libstring.o
  CC      /home/username/works/openwrt/build_dir/target-x86_64_glibc_custom/linux-x86_64/linux-6.6.30/tools/objtool/libctype.o
  CC      /home/username/works/openwrt/build_dir/target-x86_64_glibc_custom/linux-x86_64/linux-6.6.30/tools/objtool/str_error_r.o
  CC      /home/username/works/openwrt/build_dir/target-x86_64_glibc_custom/linux-x86_64/linux-6.6.30/tools/objtool/librbtree.o
  HOSTLD  scripts/mod/modpost
  CC      kernel/bounds.s
  CHKSHA1 include/linux/atomic/atomic-arch-fallback.h
  CHKSHA1 include/linux/atomic/atomic-instrumented.h
  CHKSHA1 include/linux/atomic/atomic-long.h
  UPD     include/generated/timeconst.h
  UPD     include/generated/bounds.h
  CC      arch/x86/kernel/asm-offsets.s
  LD      /home/username/works/openwrt/build_dir/target-x86_64_glibc_custom/linux-x86_64/linux-6.6.30/tools/objtool/arch/x86/objtool-in.o
  UPD     include/generated/asm-offsets.h
  LD      /home/username/works/openwrt/build_dir/target-x86_64_glibc_custom/linux-x86_64/linux-6.6.30/tools/objtool/objtool-in.o
  LINK    /home/username/works/openwrt/build_dir/target-x86_64_glibc_custom/linux-x86_64/linux-6.6.30/tools/objtool/objtool
/usr/bin/ld: /home/username/works/openwrt/staging_dir/host/lib/libelf.a(elf_begin.o): in function `elf_begin':
elf_begin.c:(.text+0x1878): undefined reference to `rpl_fcntl'
collect2: error: ld returned 1 exit status
make[8]: *** [Makefile:71: /home/username/works/openwrt/build_dir/target-x86_64_glibc_custom/linux-x86_64/linux-6.6.30/tools/objtool/objtool] Error 1
make[7]: *** [Makefile:73: objtool] Error 2
make[6]: *** [/home/username/works/openwrt/build_dir/target-x86_64_glibc_custom/linux-x86_64/linux-6.6.30/Makefile:1355: tools/objtool] Error 2
make[5]: *** [Makefile:234: __sub-make] Error 2
make[5]: Leaving directory '/home/username/works/openwrt/build_dir/target-x86_64_glibc_custom/linux-x86_64/linux-6.6.30'
make[4]: *** [Makefile:26: /home/username/works/openwrt/build_dir/target-x86_64_glibc_custom/linux-x86_64/linux-6.6.30/.modules] Error 2
make[4]: Leaving directory '/home/username/works/openwrt/target/linux/x86'
make[3]: *** [Makefile:11: compile] Error 2
make[3]: Leaving directory '/home/username/works/openwrt/target/linux'
time: target/linux/compile#22.63#34.18#41.77
    ERROR: target/linux failed to build.
make[2]: *** [target/Makefile:32: target/linux/compile] Error 1
make[2]: Leaving directory '/home/username/works/openwrt'
make[1]: *** [target/Makefile:25: /home/username/works/openwrt/staging_dir/target-x86_64_glibc_custom/stamp/.target_compile] Error 2
make[1]: Leaving directory '/home/username/works/openwrt'
make: *** [/home/username/works/openwrt/include/toplevel.mk:233: world] Error 2

@httpstorm
Copy link
Contributor

@mpratt14

macOS 14.4.1 Intel:

  • gnulib builds fine
  • elfutils fails:
make tools/elfutils/{clean,compile} -j 1 V=s
…
/usr/bin/env bash ../libtool  --tag=CC   --mode=link /Volumes/test/m/openwrt/staging_dir/host/bin/gcc -std=gnu99 -Wall -Wshadow -Wformat=2 -Wold-style-definition -Wstrict-prototypes    -Wnull-dereference -Wimplicit-fallthrough  -Werror -Wunused -Wextra    -D_FORTIFY_SOURCE=3 -O2 -I/Volumes/test/m/openwrt/staging_dir/host/include  -I/opt/homebrew/include -Wno-error -fPIC -fno-addrsig -Wl,-rpath-link,../libelf:../libdw  -L/Volumes/test/m/openwrt/staging_dir/host/lib  -o elflint elflint.o ../libebl/libebl.la ../backends/libebl_backends.la ../libcpu/libcpu.la ../libdw/libdw.la -lz  ../libelf/libelf.la -lz  -ldl -lpthread ../libelf/libelf.la -lz  ../lib/libeu.la   /Volumes/test/m/openwrt/build_dir/host/elfutils-0.191/libgnu/libgnu.la
OpenWrt-libtool: link: /Volumes/test/m/openwrt/staging_dir/host/bin/gcc -std=gnu99 -Wall -Wshadow -Wformat=2 -Wold-style-definition -Wstrict-prototypes -Wnull-dereference -Wimplicit-fallthrough -Werror -Wunused -Wextra -D_FORTIFY_SOURCE=3 -O2 -I/Volumes/test/m/openwrt/staging_dir/host/include -I/opt/homebrew/include -Wno-error -fPIC -fno-addrsig -Wl,-rpath-link -Wl,../libelf:../libdw -o elflint elflint.o  -L/Volumes/test/m/openwrt/staging_dir/host/lib ../libebl/.libs/libebl.a ../backends/.libs/libebl_backends.a ../libcpu/.libs/libcpu.a ../libdw/.libs/libdw.a -ldl ../libelf/.libs/libelf.a -lpthread -lz ../lib/.libs/libeu.a /Volumes/test/m/openwrt/build_dir/host/elfutils-0.191/libgnu/.libs/libgnu.a
ld: unknown options: -rpath-link 
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[5]: *** [Makefile:1655: elflint] Error 1
make[4]: *** [Makefile:1480: all-recursive] Error 1
make[3]: *** [Makefile:1387: all] Error 2
make[3]: Leaving directory '/Volumes/test/m/openwrt/build_dir/host/elfutils-0.191'
make[2]: *** [Makefile:103: /Volumes/test/m/openwrt/build_dir/host/elfutils-0.191/.built] Error 2
make[2]: Leaving directory '/Volumes/test/m/openwrt/tools/elfutils'

x64.2024-05-03.01-gnulib-macos.txt
x64.2024-05-03.02-elfutils-macos.txt

@mpratt14
Copy link
Contributor Author

mpratt14 commented May 3, 2024

yeah the CI showed the same thing ...

@mpratt14
Copy link
Contributor Author

mpratt14 commented May 3, 2024

ok let's give it another try, this time there are more variable overrides...

the rpath-link option is for shared libraries only, and we no longer build them as shared here...
its a shame that the --disable-shared configure option does nothing...

@httpstorm can you also show output of this

nm staging_dir/host/lib/libelf.a | grep rpl
grep ^REPLACE_ build_dir/host/elfutils-0.191/libgnu/Makefile | grep 1

@mpratt14
Copy link
Contributor Author

mpratt14 commented May 3, 2024

ah great... more linking problems

@mpratt14
Copy link
Contributor Author

mpratt14 commented May 3, 2024

@httpstorm now I need to see.....

nm build_dir/host/elfutils-0.191/libebl/.libs/libebl.a | grep default_

@mpratt14
Copy link
Contributor Author

mpratt14 commented May 4, 2024

nevermind I got it, they are defined with strong_alias but that's disabled for macos here

$ cat libebl/eblopenbackend.c | grep default_none
static bool default_none_reloc_p (int reloc);
  result->none_reloc_p = default_none_reloc_p;
strong_alias (default_copy_reloc_p, default_none_reloc_p)

$ cat libebl/eblopenbackend.c | grep default_relative
static bool default_relative_reloc_p (int reloc);
  result->relative_reloc_p = default_relative_reloc_p;
strong_alias (default_copy_reloc_p, default_relative_reloc_p)

@httpstorm
Copy link
Contributor

httpstorm commented May 4, 2024

@mpratt14

/usr/bin/env bash ../libtool  --tag=CC   --mode=link /Volumes/test/m/openwrt/staging_dir/host/bin/gcc -std=gnu99 -Wall -Wshadow -Wformat=2 -Wold-style-definition -Wstrict-prototypes    -Wnull-dereference -Wimplicit-fallthrough  -Werror -Wunused -Wextra    -D_FORTIFY_SOURCE=3 -O2 -I/Volumes/test/m/openwrt/staging_dir/host/include  -I/opt/homebrew/include -Wno-error -fPIC -fno-addrsig  -L/Volumes/test/m/openwrt/staging_dir/host/lib  -o elflint elflint.o ../libebl/libebl.la ../backends/libebl_backends.la ../libcpu/libcpu.la ../libdw/libdw.la -lz  ../libelf/libelf.la -lz  -ldl -lpthread ../libelf/libelf.la -lz  ../lib/libeu.la   /Volumes/test/m/openwrt/build_dir/host/elfutils-0.191/libgnu/libgnu.la
OpenWrt-libtool: link: /Volumes/test/m/openwrt/staging_dir/host/bin/gcc -std=gnu99 -Wall -Wshadow -Wformat=2 -Wold-style-definition -Wstrict-prototypes -Wnull-dereference -Wimplicit-fallthrough -Werror -Wunused -Wextra -D_FORTIFY_SOURCE=3 -O2 -I/Volumes/test/m/openwrt/staging_dir/host/include -I/opt/homebrew/include -Wno-error -fPIC -fno-addrsig -o elflint elflint.o  -L/Volumes/test/m/openwrt/staging_dir/host/lib ../libebl/.libs/libebl.a ../backends/.libs/libebl_backends.a ../libcpu/.libs/libcpu.a ../libdw/.libs/libdw.a -ldl ../libelf/.libs/libelf.a -lpthread -lz ../lib/.libs/libeu.a /Volumes/test/m/openwrt/build_dir/host/elfutils-0.191/libgnu/.libs/libgnu.a
Undefined symbols for architecture x86_64:
  "_default_none_reloc_p", referenced from:
      _openbackend in libebl.a[2](eblopenbackend.o)
      _openbackend in libebl.a[2](eblopenbackend.o)
  "_default_relative_reloc_p", referenced from:
      _openbackend in libebl.a[2](eblopenbackend.o)
      _openbackend in libebl.a[2](eblopenbackend.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[5]: *** [Makefile:1655: elflint] Error 1
make[4]: *** [Makefile:1480: all-recursive] Error 1
make[3]: *** [Makefile:1387: all] Error 2

x64.2024-05-03.03-elfutils-macos.txt

nm build_dir/host/elfutils-0.191/libebl/.libs/libebl.a | grep default_
00000000000008d0 t _default_abi_cfi
00000000000006d0 t _default_auxv_info
0000000000000820 t _default_bss_plt_p
00000000000008a0 t _default_check_object_attribute
00000000000008c0 t _default_check_reloc_target_type
0000000000000640 t _default_check_special_section
00000000000007f0 t _default_check_special_symbol
0000000000000810 t _default_check_st_other_bits
00000000000007e0 t _default_copy_reloc_p
00000000000006c0 t _default_core_note
00000000000006a0 t _default_core_note_type_name
0000000000000800 t _default_data_marker_symbol
00000000000006f0 t _default_debugscn_p
0000000000001580 s _default_debugscn_p.dwarf_scn_names
00000000000008e0 t _default_destr
0000000000000680 t _default_dynamic_tag_check
0000000000000670 t _default_dynamic_tag_name
00000000000005d0 t _default_gotpc_reloc_check
0000000000000620 t _default_machine_flag_check
0000000000000610 t _default_machine_flag_name
0000000000000630 t _default_machine_section_flag_check
                 U _default_none_reloc_p
00000000000006e0 t _default_object_note
00000000000006b0 t _default_object_note_type_name
0000000000000690 t _default_osabi_name
0000000000000840 t _default_register_info
                 U _default_relative_reloc_p
00000000000005c0 t _default_reloc_simple_type
00000000000005a0 t _default_reloc_type_check
0000000000000590 t _default_reloc_type_name
00000000000005b0 t _default_reloc_valid_use
0000000000000830 t _default_return_value_location
0000000000000600 t _default_section_name
00000000000005f0 t _default_section_type_name
00000000000005e0 t _default_segment_type_name
0000000000000660 t _default_symbol_binding_name
0000000000000650 t _default_symbol_type_name
cat libebl/eblopenbackend.c | grep default_none
static bool default_none_reloc_p (int reloc);
  result->none_reloc_p = default_none_reloc_p;
strong_alias (default_copy_reloc_p, default_none_reloc_p)

cat libebl/eblopenbackend.c | grep default_relative
static bool default_relative_reloc_p (int reloc);
  result->relative_reloc_p = default_relative_reloc_p;
strong_alias (default_copy_reloc_p, default_relative_reloc_p)

@mpratt14
Copy link
Contributor Author

mpratt14 commented May 4, 2024

@httpstorm now I'm confused... can you show this again with the new push?

nm build_dir/host/elfutils-0.191/libebl/.libs/libebl.a | grep default_

@mpratt14
Copy link
Contributor Author

mpratt14 commented May 4, 2024

small rebase because I'm suspicious of the CI's results...

all 3 functions have the exact same representation now:

$ grep -rnw build_dir/host/elfutils-0.191 -e 'default_copy_reloc_p'
grep: build_dir/host/elfutils-0.191/src/elfcmp: binary file matches
grep: build_dir/host/elfutils-0.191/src/elflint: binary file matches
grep: build_dir/host/elfutils-0.191/src/unstrip: binary file matches
grep: build_dir/host/elfutils-0.191/src/stack: binary file matches
grep: build_dir/host/elfutils-0.191/src/srcfiles: binary file matches
grep: build_dir/host/elfutils-0.191/libebl/eblopenbackend.o: binary file matches
build_dir/host/elfutils-0.191/libebl/eblopenbackend.c:200:static bool default_copy_reloc_p (int reloc);
build_dir/host/elfutils-0.191/libebl/eblopenbackend.c:253:  result->copy_reloc_p = default_copy_reloc_p;
build_dir/host/elfutils-0.191/libebl/eblopenbackend.c:633:default_copy_reloc_p (int reloc __attribute__ ((unused)))
grep: build_dir/host/elfutils-0.191/libebl/.libs/libebl.a: binary file matches
build_dir/host/elfutils-0.191/libebl/ChangeLog:1112:    (default_copy_reloc_p): New function.
grep: build_dir/host/elfutils-0.191/libdw/.libs/libdw.a: binary file matches


$ grep -rnw build_dir/host/elfutils-0.191 -e 'default_none_reloc_p'
grep: build_dir/host/elfutils-0.191/src/elfcmp: binary file matches
grep: build_dir/host/elfutils-0.191/src/elflint: binary file matches
grep: build_dir/host/elfutils-0.191/src/unstrip: binary file matches
grep: build_dir/host/elfutils-0.191/src/stack: binary file matches
grep: build_dir/host/elfutils-0.191/src/srcfiles: binary file matches
grep: build_dir/host/elfutils-0.191/libebl/eblopenbackend.o: binary file matches
build_dir/host/elfutils-0.191/libebl/eblopenbackend.c:201:static bool default_none_reloc_p (int reloc);
build_dir/host/elfutils-0.191/libebl/eblopenbackend.c:254:  result->none_reloc_p = default_none_reloc_p;
build_dir/host/elfutils-0.191/libebl/eblopenbackend.c:639:default_none_reloc_p (int reloc __attribute__ ((unused)))
grep: build_dir/host/elfutils-0.191/libebl/.libs/libebl.a: binary file matches
build_dir/host/elfutils-0.191/libebl/ChangeLog:736:     * eblopenbackend.c (default_none_reloc_p): New function.
grep: build_dir/host/elfutils-0.191/libdw/.libs/libdw.a: binary file matches


$ grep -rnw build_dir/host/elfutils-0.191 -e 'default_relative_reloc_p'
grep: build_dir/host/elfutils-0.191/src/elfcmp: binary file matches
grep: build_dir/host/elfutils-0.191/src/elflint: binary file matches
grep: build_dir/host/elfutils-0.191/src/unstrip: binary file matches
grep: build_dir/host/elfutils-0.191/src/stack: binary file matches
grep: build_dir/host/elfutils-0.191/src/srcfiles: binary file matches
grep: build_dir/host/elfutils-0.191/libebl/eblopenbackend.o: binary file matches
build_dir/host/elfutils-0.191/libebl/eblopenbackend.c:202:static bool default_relative_reloc_p (int reloc);
build_dir/host/elfutils-0.191/libebl/eblopenbackend.c:255:  result->relative_reloc_p = default_relative_reloc_p;
build_dir/host/elfutils-0.191/libebl/eblopenbackend.c:645:default_relative_reloc_p (int reloc __attribute__ ((unused)))
grep: build_dir/host/elfutils-0.191/libebl/.libs/libebl.a: binary file matches
build_dir/host/elfutils-0.191/libebl/ChangeLog:727:     * eblopenbackend.c (default_relative_reloc_p): New function.
grep: build_dir/host/elfutils-0.191/libdw/.libs/libdw.a: binary file matches

@nbd168
Copy link
Member

nbd168 commented May 4, 2024

What's your goal with this PR? On macOS, a lot of gnulib stuff is needed for libelf, and it seems more messy to me to try to deal with that in each package that depends on it. Wouldn't it be better to continue linking gnulib into libelf, but find a way to make the extra symbols hidden?

@httpstorm
Copy link
Contributor

httpstorm commented May 4, 2024

@mpratt14

/usr/bin/env bash ../libtool  --tag=CC   --mode=link /Volumes/test/m/openwrt/staging_dir/host/bin/gcc -std=gnu99 -Wall -Wshadow -Wformat=2 -Wold-style-definition -Wstrict-prototypes    -Wnull-dereference -Wimplicit-fallthrough  -Werror -Wunused -Wextra    -D_FORTIFY_SOURCE=3 -O2 -I/Volumes/test/m/openwrt/staging_dir/host/include  -I/opt/homebrew/include -Wno-error -fPIC -fno-addrsig  -L/Volumes/test/m/openwrt/staging_dir/host/lib  -o unstrip unstrip.o ../libebl/libebl.la ../backends/libebl_backends.la ../libcpu/libcpu.la ../libelf/libelf.la -lz  ../libdw/libdw.la -lz  ../libelf/libelf.la -lz  -ldl -lpthread ../lib/libeu.la   /Volumes/test/m/openwrt/build_dir/host/elfutils-0.191/libgnu/libgnu.la
OpenWrt-libtool: link: /Volumes/test/m/openwrt/staging_dir/host/bin/gcc -std=gnu99 -Wall -Wshadow -Wformat=2 -Wold-style-definition -Wstrict-prototypes -Wnull-dereference -Wimplicit-fallthrough -Werror -Wunused -Wextra -D_FORTIFY_SOURCE=3 -O2 -I/Volumes/test/m/openwrt/staging_dir/host/include -I/opt/homebrew/include -Wno-error -fPIC -fno-addrsig -o unstrip unstrip.o  -L/Volumes/test/m/openwrt/staging_dir/host/lib ../libebl/.libs/libebl.a ../backends/.libs/libebl_backends.a ../libcpu/.libs/libcpu.a ../libdw/.libs/libdw.a ../libelf/.libs/libelf.a -lz -ldl -lpthread ../lib/.libs/libeu.a /Volumes/test/m/openwrt/build_dir/host/elfutils-0.191/libgnu/.libs/libgnu.a
Undefined symbols for architecture x86_64:
  "_rpl_fts_close$INODE64", referenced from:
      _dwfl_linux_kernel_report_offline in libdw.a[189](linux-kernel-modules.o)
      _dwfl_linux_kernel_report_modules in libdw.a[189](linux-kernel-modules.o)
  "_rpl_fts_open$INODE64", referenced from:
      _dwfl_linux_kernel_report_offline in libdw.a[189](linux-kernel-modules.o)
      _dwfl_linux_kernel_report_modules in libdw.a[189](linux-kernel-modules.o)
  "_rpl_fts_read$INODE64", referenced from:
      _dwfl_linux_kernel_report_offline in libdw.a[189](linux-kernel-modules.o)
      _dwfl_linux_kernel_report_offline in libdw.a[189](linux-kernel-modules.o)
      _dwfl_linux_kernel_report_modules in libdw.a[189](linux-kernel-modules.o)
      _dwfl_linux_kernel_report_modules in libdw.a[189](linux-kernel-modules.o)
  "_rpl_fts_set$INODE64", referenced from:
      _dwfl_linux_kernel_report_offline in libdw.a[189](linux-kernel-modules.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[5]: *** [Makefile:1699: unstrip] Error 1
make[4]: *** [Makefile:1480: all-recursive] Error 1
make[3]: *** [Makefile:1387: all] Error 2

x64.2024-05-04.01-elfutils-macos.txt

nm build_dir/host/elfutils-0.191/libebl/.libs/libebl.a | grep default_

00000000000008f0 t _default_abi_cfi
00000000000006d0 t _default_auxv_info
0000000000000840 t _default_bss_plt_p
00000000000008c0 t _default_check_object_attribute
00000000000008e0 t _default_check_reloc_target_type
0000000000000640 t _default_check_special_section
0000000000000810 t _default_check_special_symbol
0000000000000830 t _default_check_st_other_bits
00000000000007e0 t _default_copy_reloc_p
00000000000006c0 t _default_core_note
00000000000006a0 t _default_core_note_type_name
0000000000000820 t _default_data_marker_symbol
00000000000006f0 t _default_debugscn_p
00000000000015a0 s _default_debugscn_p.dwarf_scn_names
0000000000000900 t _default_destr
0000000000000680 t _default_dynamic_tag_check
0000000000000670 t _default_dynamic_tag_name
00000000000005d0 t _default_gotpc_reloc_check
0000000000000620 t _default_machine_flag_check
0000000000000610 t _default_machine_flag_name
0000000000000630 t _default_machine_section_flag_check
00000000000007f0 t _default_none_reloc_p
00000000000006e0 t _default_object_note
00000000000006b0 t _default_object_note_type_name
0000000000000690 t _default_osabi_name
0000000000000860 t _default_register_info
0000000000000800 t _default_relative_reloc_p
00000000000005c0 t _default_reloc_simple_type
00000000000005a0 t _default_reloc_type_check
0000000000000590 t _default_reloc_type_name
00000000000005b0 t _default_reloc_valid_use
0000000000000850 t _default_return_value_location
0000000000000600 t _default_section_name
00000000000005f0 t _default_section_type_name
00000000000005e0 t _default_segment_type_name
0000000000000660 t _default_symbol_binding_name
0000000000000650 t _default_symbol_type_name
grep -rnw build_dir/host/elfutils-0.191 -e 'default_copy_reloc_p'
build_dir/host/elfutils-0.191/libebl/ChangeLog:1112:	(default_copy_reloc_p): New function.
build_dir/host/elfutils-0.191/libebl/eblopenbackend.c:200:static bool default_copy_reloc_p (int reloc);
build_dir/host/elfutils-0.191/libebl/eblopenbackend.c:253:  result->copy_reloc_p = default_copy_reloc_p;
build_dir/host/elfutils-0.191/libebl/eblopenbackend.c:633:default_copy_reloc_p (int reloc __attribute__ ((unused)))

grep -rnw build_dir/host/elfutils-0.191 -e 'default_none_reloc_p'
build_dir/host/elfutils-0.191/libebl/ChangeLog:736:	* eblopenbackend.c (default_none_reloc_p): New function.
build_dir/host/elfutils-0.191/libebl/eblopenbackend.c:201:static bool default_none_reloc_p (int reloc);
build_dir/host/elfutils-0.191/libebl/eblopenbackend.c:254:  result->none_reloc_p = default_none_reloc_p;
build_dir/host/elfutils-0.191/libebl/eblopenbackend.c:639:default_none_reloc_p (int reloc __attribute__ ((unused)))

grep -rnw build_dir/host/elfutils-0.191 -e 'default_relative_reloc_p'
build_dir/host/elfutils-0.191/libebl/ChangeLog:727:	* eblopenbackend.c (default_relative_reloc_p): New function.
build_dir/host/elfutils-0.191/libebl/eblopenbackend.c:202:static bool default_relative_reloc_p (int reloc);
build_dir/host/elfutils-0.191/libebl/eblopenbackend.c:255:  result->relative_reloc_p = default_relative_reloc_p;
build_dir/host/elfutils-0.191/libebl/eblopenbackend.c:645:default_relative_reloc_p (int reloc __attribute__ ((unused)))

I see you just made more changes, I'll retest.

@httpstorm
Copy link
Contributor

@mpratt14

/usr/bin/env bash ../libtool  --tag=CC   --mode=compile /Volumes/test/m/openwrt/staging_dir/host/bin/gcc -D_GNU_SOURCE -DHAVE_CONFIG_H -DLOCALEDIR='"/Volumes/test/m/openwrt/staging_dir/host/share/locale"' -I. -I..  -I../libgnu -I../libgnu -I. -I. -I../lib -I.. -I/Volumes/test/m/openwrt/staging_dir/host/include  -std=gnu99 -Wall -Wshadow -Wformat=2 -Wold-style-definition -Wstrict-prototypes    -Wnull-dereference -Wimplicit-fallthrough  -Werror -Wunused -Wextra     -D_FORTIFY_SOURCE=3 -O2 -I/Volumes/test/m/openwrt/staging_dir/host/include  -I/opt/homebrew/include -Wno-error -fPIC -fno-addrsig -c -o elf_getshdrnum.lo elf_getshdrnum.c
OpenWrt-libtool: compile:  /Volumes/test/m/openwrt/staging_dir/host/bin/gcc -D_GNU_SOURCE -DHAVE_CONFIG_H -DLOCALEDIR=\"/Volumes/test/m/openwrt/staging_dir/host/share/locale\" -I. -I.. -I../libgnu -I../libgnu -I. -I. -I../lib -I.. -I/Volumes/test/m/openwrt/staging_dir/host/include -std=gnu99 -Wall -Wshadow -Wformat=2 -Wold-style-definition -Wstrict-prototypes -Wnull-dereference -Wimplicit-fallthrough -Werror -Wunused -Wextra -D_FORTIFY_SOURCE=3 -O2 -I/Volumes/test/m/openwrt/staging_dir/host/include -I/opt/homebrew/include -Wno-error -fPIC -fno-addrsig -c elf_getshdrnum.c -o elf_getshdrnum.o
In file included from elf_getshdrnum.c:38:
In file included from ./libelfP.h:43:
../lib/system.h:125:9: warning: 'gettext_noop' macro redefined [-Wmacro-redefined]
#define gettext_noop(Str) Str
        ^
../libgnu/gettext.h:109:9: note: previous definition is here
#define gettext_noop(String) String
        ^
elf_getshdrnum.c:87:1: error: aliases are not supported on darwin
strong_alias (elf_getshdrnum, elf_getshnum)
^
../libgnu/eu-config.h:70:54: note: expanded from macro 'strong_alias'
  extern __typeof__ (name) aliasname __attribute__ ((alias (#name)));
                                                     ^
1 warning and 1 error generated.
make[5]: *** [Makefile:1765: elf_getshdrnum.lo] Error 1
make[4]: *** [Makefile:1480: all-recursive] Error 1
make[3]: *** [Makefile:1387: all] Error 2

x64.2024-05-04.02-elfutils-macos.txt

nm build_dir/host/elfutils-0.191/libebl/.libs/libebl.a | grep default_
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/nm: error: build_dir/host/elfutils-0.191/libebl/.libs/libebl.a: No such file or directory
grep -rnw build_dir/host/elfutils-0.191 -e 'default_copy_reloc_p'
build_dir/host/elfutils-0.191/libebl/ChangeLog:1112:	(default_copy_reloc_p): New function.
build_dir/host/elfutils-0.191/libebl/eblopenbackend.c:200:static bool default_copy_reloc_p (int reloc);
build_dir/host/elfutils-0.191/libebl/eblopenbackend.c:253:  result->copy_reloc_p = default_copy_reloc_p;
build_dir/host/elfutils-0.191/libebl/eblopenbackend.c:633:default_copy_reloc_p (int reloc __attribute__ ((unused)))
build_dir/host/elfutils-0.191/libebl/eblopenbackend.c:637:strong_alias (default_copy_reloc_p, default_none_reloc_p)
build_dir/host/elfutils-0.191/libebl/eblopenbackend.c:638:strong_alias (default_copy_reloc_p, default_relative_reloc_p)

grep -rnw build_dir/host/elfutils-0.191 -e 'default_none_reloc_p'
build_dir/host/elfutils-0.191/libebl/ChangeLog:736:	* eblopenbackend.c (default_none_reloc_p): New function.
build_dir/host/elfutils-0.191/libebl/eblopenbackend.c:201:static bool default_none_reloc_p (int reloc);
build_dir/host/elfutils-0.191/libebl/eblopenbackend.c:254:  result->none_reloc_p = default_none_reloc_p;
build_dir/host/elfutils-0.191/libebl/eblopenbackend.c:637:strong_alias (default_copy_reloc_p, default_none_reloc_p)

grep -rnw build_dir/host/elfutils-0.191 -e 'default_relative_reloc_p'
build_dir/host/elfutils-0.191/libebl/ChangeLog:727:	* eblopenbackend.c (default_relative_reloc_p): New function.
build_dir/host/elfutils-0.191/libebl/eblopenbackend.c:202:static bool default_relative_reloc_p (int reloc);
build_dir/host/elfutils-0.191/libebl/eblopenbackend.c:255:  result->relative_reloc_p = default_relative_reloc_p;
build_dir/host/elfutils-0.191/libebl/eblopenbackend.c:638:strong_alias (default_copy_reloc_p, default_relative_reloc_p)

@mpratt14
Copy link
Contributor Author

mpratt14 commented May 4, 2024

What's your goal with this PR? On macOS, a lot of gnulib stuff is needed for libelf, and it seems more messy to me to try to deal with that in each package that depends on it. Wouldn't it be better to continue linking gnulib into libelf, but find a way to make the extra symbols hidden?

I'm running on the philosophy of "let the linker decide each time", and while it may be common for multiple libraries to provide the same function, it's the opposite of common for the same library to provide the same function again like we saw with the issue mentioned. To me, that stuck out as a build design flaw more than a coincidence. Also, I don't think it's reasonable to stuff a built library with functions already available on the host machine's standard libraries. Gnulib is designed to cover its own dependencies as needed, and several of the functions aren't needed. If this were to happen again, but with a module that we actually needed to keep, it would mean another huge patch for gnulib to fix (the right way) or some wild workaround in that program/package (the quick and dirty way) and probably neither upstream project would like those changes so we would be stuck with it.

I'm hoping it's easy or even not necessary to include gnulib for other packages that depend on libelf, but if it turns out to be ridiculous I'll just let go of the idea. I was also thinking about the possibility of installing them side-by-side instead of linking them together, so only an extra link flag would have to be added to a package...

But we are currently stuck with just building some of the binaries on macOS, which is another thing I wanted to see happen if possible...

@mpratt14
Copy link
Contributor Author

mpratt14 commented May 4, 2024

error: aliases are not supported on darwin

well I lost that bet

I'm being slightly mislead, don't believe everything on forums 😆

@httpstorm
Copy link
Contributor

@mpratt14
There are sometimes old materials and incompetent people. Stackoverflow is by far my best place to find good information.
I will go on vacation for the weekend, maybe longer. You can try my runner-test repo in case you want to experiment on the CI manually. If you change to the old macOS 12, it should work. Latest became macOS 14 ARM and fails to build. Maybe I should setup paths to match the OpenWRT configuration, but I was too busy to test. Contributions are welcome. Currently I'm only using symlinks, which works fine on Intel based Macs. They are way slower. The provided shell over netcat is limited. If you need a real terminal and SFTP/SCP, an outgoing SSH tunnel with port forwarding should help. Just try not to expose your keys. Don't save them to a forked repo or send to the runner unencrypted.

Best of luck! I admire your motivation to experiment and improve. 😊
PS: I'll git that last change a test.

@mpratt14
Copy link
Contributor Author

mpratt14 commented May 4, 2024

thanks for the participation Georgi, even if we might be wasting time...

I'm a little apprehensive to try the reverse shell runner, normal CI runs are giving enough info this time anyway...

at the very least, your system's errors agree with the CI... except for those 3 functions that should be treated the same... but now I got rid of them...

@httpstorm
Copy link
Contributor

@mpratt14

Undefined symbols for architecture x86_64:
  "_rpl_fts_close$INODE64", referenced from:
      _dwfl_linux_kernel_report_offline in libdw.a[189](linux-kernel-modules.o)
      _dwfl_linux_kernel_report_modules in libdw.a[189](linux-kernel-modules.o)
  "_rpl_fts_open$INODE64", referenced from:
      _dwfl_linux_kernel_report_offline in libdw.a[189](linux-kernel-modules.o)
      _dwfl_linux_kernel_report_modules in libdw.a[189](linux-kernel-modules.o)
  "_rpl_fts_read$INODE64", referenced from:
      _dwfl_linux_kernel_report_offline in libdw.a[189](linux-kernel-modules.o)
      _dwfl_linux_kernel_report_offline in libdw.a[189](linux-kernel-modules.o)
      _dwfl_linux_kernel_report_modules in libdw.a[189](linux-kernel-modules.o)
      _dwfl_linux_kernel_report_modules in libdw.a[189](linux-kernel-modules.o)
  "_rpl_fts_set$INODE64", referenced from:
      _dwfl_linux_kernel_report_offline in libdw.a[189](linux-kernel-modules.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

x64.2024-05-04.03-elfutils-macos.txt

@mpratt14 mpratt14 force-pushed the elfutils-unlink-libelf branch 2 times, most recently from ca765be to e3309d3 Compare May 4, 2024 20:49
@mpratt14
Copy link
Contributor Author

mpratt14 commented May 4, 2024

@httpstorm so if you could show your system's fts header maybe that would show whats going on...

find /usr/lib /usr/local/include /usr/include | grep fts.h

@httpstorm
Copy link
Contributor

httpstorm commented May 5, 2024

@mpratt14

find /usr/lib /usr/local/include /usr/include | grep fts.h
find: ‘/usr/include’: No such file or directory

find /usr | grep fts.h
find: ‘/usr/sbin/authserver’: Permission denied
/usr/local/Cellar/libwebsockets/4.3.3/include/libwebsockets/lws-fts.h

find /Applications/Xcode.app | grep 'fts\.h'
/Applications/Xcode.app/Contents/Developer/Platforms/XROS.platform/Developer/SDKs/XROS.sdk/usr/include/fts.h
/Applications/Xcode.app/Contents/Developer/Platforms/XRSimulator.platform/Developer/SDKs/XRSimulator.sdk/usr/include/fts.h
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/include/fts.h
/Applications/Xcode.app/Contents/Developer/Platforms/WatchSimulator.platform/Developer/SDKs/WatchSimulator.sdk/usr/include/fts.h
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/fts.h
/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk/usr/include/fts.h
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/fts.h
/Applications/Xcode.app/Contents/Developer/Platforms/WatchOS.platform/Developer/SDKs/WatchOS.sdk/usr/include/fts.h
/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator.sdk/usr/include/fts.h

It's here

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/fts.h

fts.h

@mpratt14
Copy link
Contributor Author

mpratt14 commented May 5, 2024

@httpstorm ready for you to give it a try again

@mpratt14
Copy link
Contributor Author

I am quite alarmed by the amount and recently with the rate of fixes for macOS that are being added just further complicating any updates in future.

@robimarko that's exactly why I'm trying to do extra preventative maintenance now instead of waiting until the next release... It's clear to see how much of a mess it is, so I want to make the next future version bump very easy...

If it seems like this is happening all at once, it's just because the way support for macOS was added in the first place was such a large change by itself, the clean up is naturally a little chaotic.

After this, I'm going to post a PR for greatly reducing the size of the patch. Making robust variable overrides in our Makefile in this PR is part of that process.

Some lines will still look fairly complex at first glance, but they can be explained easily once understood. I think a few Makefile complexities will be worth it to end up with 500 less lines in tools/elfutils in exchange...

@mpratt14
Copy link
Contributor Author

by the way, I should add... I talk a lot about reducing the size of the patch yet this PR is basically only adding lines...

However, that's only because of trying to build binaries again after they were disabled, except for the ones that would conflict with the toolchain as described in the commit
f64bd4b

@robimarko
Copy link
Contributor

I am not talking specifically about this PR but the amount of macOS fixes that are constantly being added in general and those are really getting out of hand

@mpratt14
Copy link
Contributor Author

so does this look good? should I rebase so that I can put the added gnulib module alphabetically without conflict?

@mpratt14 mpratt14 force-pushed the elfutils-unlink-libelf branch 2 times, most recently from fd0f7a8 to 0e304ec Compare May 19, 2024 05:15
@mpratt14
Copy link
Contributor Author

rebased, and updated commit messages

@robimarko
Copy link
Contributor

My Mac Mini at work is currently down as they are upgrading the network and VPN access so I cant test this currently

@httpstorm
Copy link
Contributor

@robimarko

My Mac Mini at work is currently down as they are upgrading the network and VPN access so I cant test this currently

Builds fine on macOS 14.5 Intel, frr too.

@robimarko
Copy link
Contributor

Well, this is breaking elfutils compilation on Fedora 40 (GCC 14.1.1)

/home/robimarko/Building/AX3600/qualcommax/staging_dir/host/bin/g++ -std=c++11 -D_GNU_SOURCE -DHAVE_CONFIG_H -DLOCALEDIR='"/home/robimarko/Building/AX3600/qualcommax/staging_dir/host/share/locale"'  -DDEBUGPRED=0 -DSRCDIR=\"/home/robimarko/Building/AX3600/qualcommax/build_dir/host/elfutils-0.191/src\" -DOBJDIR=\"/home/robimarko/Building/AX3600/qualcommax/build_dir/host/elfutils-0.191/src\" -I. -I..  -I../libgnu -I../libgnu -I. -I. -I../lib -I.. -I./../libelf -I./../libebl -I./../libdw -I./../libdwelf -I./../libdwfl -I./../libasm -I../debuginfod -I/home/robimarko/Building/AX3600/qualcommax/staging_dir/host/include  -std=c++11 -Wall -Wshadow -Wtrampolines -Wlogical-op -Wduplicated-cond -Wnull-dereference -Wimplicit-fallthrough=5 -Werror -Wunused -Wextra -Wstack-usage=262144   -D_FORTIFY_SOURCE=3  -c -o srcfiles.o srcfiles.cxx
In file included from /usr/include/c++/14/x86_64-redhat-linux/bits/os_defines.h:39,
                 from /usr/include/c++/14/x86_64-redhat-linux/bits/c++config.h:2521,
                 from /usr/include/c++/14/cstdlib:41,
                 from ../libgnu/gettext.h:56,
                 from ../libgnu/eu-config.h:62,
                 from ../config.h:2378,
                 from srcfiles.cxx:31:
/usr/include/features.h:414:4: error: #warning _FORTIFY_SOURCE requires compiling with optimization (-O) [-Werror=cpp]
  414 | #  warning _FORTIFY_SOURCE requires compiling with optimization (-O)
      |    ^~~~~~~
cc1plus: all warnings being treated as errors
make[6]: *** [Makefile:2075: srcfiles.o] Error 1
make[5]: *** [Makefile:1745: all-recursive] Error 1
make[4]: *** [Makefile:1652: all] Error 2
make[4]: Leaving directory '/home/robimarko/Building/AX3600/qualcommax/build_dir/host/elfutils-0.191'
make[3]: *** [Makefile:107: /home/robimarko/Building/AX3600/qualcommax/build_dir/host/elfutils-0.191/.built] Error 2

@mpratt14
Copy link
Contributor Author

@robimarko try adding HOST_CXXFLAGS exactly the same as HOST_CFLAGS in the elfutils makefile

@mpratt14
Copy link
Contributor Author

...and if not put -O2 in both...

@mpratt14
Copy link
Contributor Author

we should consider a default value for HOST_CXXFLAGS in rules.mk similar to HOST_CFLAGS

@robimarko
Copy link
Contributor

@mpratt14 Adding -O2 to HOST_CXXFLAGS fixes compilation

mpratt14 and others added 4 commits May 31, 2024 16:01
The gnulib fts header is meant to not be overwritten
in any way by the host system's copy of fts.h
and was therefore given a unique name instead.

This is fine if the built libgnu library is directly linked
with the target library, but if we want to keep them isolated
we end up having the definitions being mangled anyway
when the next object to link against included the fts.h header.

On some macOS platforms, the use of __DARWIN_INODE64
is messing with the link name for fts functions, resulting in:

Undefined symbols for architecture x86_64:
  "_rpl_fts_close$INODE64", referenced from:
...

Create a local fts header for gnulib
that completely blocks the macOS host fts header.

An alternative and more upstream friendly fix would be
to rename fts_.h to fts.h and add the macOS-only
include guard to that file within it's own include guard,
but that would be a massive patch, so do this for now.

Tested-by: Georgi Valkov <gvalkov@gmail.com> # macOS
Signed-off-by: Michael Pratt <mcpratt@pm.me>
Link: openwrt#15368
Signed-off-by: Robert Marko <robimarko@gmail.com>
Install binaries that are not common with binutils
instead of none at all. This adds a negligible time to the build.

Building shared libraries is disabled, so the AM_LDFLAGS can be reset
without the rpath-link option which is unrecognized by clang.

Some of the binaries depend on functions that are defined
using a "strong alias" instead of a normal definition,
but this is disabled by our patches in order to work on macOS,
so use the identical function directly instead.

Add fnmatch from gnulib with GNU extensions
which is needed for usage of the FNM_EXTMATCH flag.

Handle a "Wunused-const-variable" error with the same
preprocessor conditional used to include the function
that the variable is used in.

Ref: f64bd4b ("tools/elfutils: only build required components")
Tested-by: Georgi Valkov <gvalkov@gmail.com> # macOS
Signed-off-by: Michael Pratt <mcpratt@pm.me>
Link: openwrt#15368
Signed-off-by: Robert Marko <robimarko@gmail.com>
The compiled library resulting from importing gnulib has been
linked to libelf in order to easily cover other link dependencies.
However, this is not appropriate for linking libelf to other programs
as it bloats the resulting libelf library, and may result in
multiple defintions of symbols based on whether or not
certain modules from gnulib are included while elfutils
already has it's own definition of a function.

This is not a problem while building elfutils, because gnulib has
it's own way of creating function aliases and special declarations
that allow the linker to ignore the original function definitions,
however, when libelf is used to link to something else,
this results in an error at link time.

The gnulib manual recommended linking the libraries directly,
but those who have written it may not have considered how this
can affect the ability to link that library in other builds,
they likely assume the build targets would not be a dependency.

Fix this by removing the linking between gnulib and libelf
and instead overriding Make variables in order to add linking
between gnulib and each of the binaries provided by elfutils,
using Make functions to avoid applying it to other subdirectories.

The function tdestroy() would still be missing on macOS,
but the existence of the gnulib tsearch object having been built
is an indicator of whether or not it is needed
because it is only built conditionally by gnulib,
so include linking that object only when it exists.

Block the unnecessary replacement of some functions by gnulib
so that future linking with libelf doesn't require
the associated gnulib "rpl" prefixed functions.
These replacements are very strict in order to correct
minor bugs that don't have a real impact in almost all cases
or new standards requirements that are not yet in effect or used.

Tested-by: Georgi Valkov <gvalkov@gmail.com> # macOS
Signed-off-by: Michael Pratt <mcpratt@pm.me>
Link: openwrt#15368
Signed-off-by: Robert Marko <robimarko@gmail.com>
Trying to compile elfutils on Fedora 40 with GCC 14.1.1 will fail with:
/home/robimarko/Building/AX3600/qualcommax/staging_dir/host/bin/g++ -std=c++11 -D_GNU_SOURCE -DHAVE_CONFIG_H -DLOCALEDIR='"/home/robimarko/Building/AX3600/qualcommax/staging_dir/host/share/locale"'  -DDEBUGPRED=0 -DSRCDIR=\"/home/robimarko/Building/AX3600/qualcommax/build_dir/host/elfutils-0.191/src\" -DOBJDIR=\"/home/robimarko/Building/AX3600/qualcommax/build_dir/host/elfutils-0.191/src\" -I. -I..  -I../libgnu -I../libgnu -I. -I. -I../lib -I.. -I./../libelf -I./../libebl -I./../libdw -I./../libdwelf -I./../libdwfl -I./../libasm -I../debuginfod -I/home/robimarko/Building/AX3600/qualcommax/staging_dir/host/include  -std=c++11 -Wall -Wshadow -Wtrampolines -Wlogical-op -Wduplicated-cond -Wnull-dereference -Wimplicit-fallthrough=5 -Werror -Wunused -Wextra -Wstack-usage=262144   -D_FORTIFY_SOURCE=3  -c -o srcfiles.o srcfiles.cxx
In file included from /usr/include/c++/14/x86_64-redhat-linux/bits/os_defines.h:39,
                 from /usr/include/c++/14/x86_64-redhat-linux/bits/c++config.h:2521,
                 from /usr/include/c++/14/cstdlib:41,
                 from ../libgnu/gettext.h:56,
                 from ../libgnu/eu-config.h:62,
                 from ../config.h:2378,
                 from srcfiles.cxx:31:
/usr/include/features.h:414:4: error: #warning _FORTIFY_SOURCE requires compiling with optimization (-O) [-Werror=cpp]
  414 | #  warning _FORTIFY_SOURCE requires compiling with optimization (-O)
      |    ^~~~~~~
cc1plus: all warnings being treated as errors

So, lets do as the error says and pass -O2 in HOST_CXXFLAGS like we already
do by default in HOST_CFLAGS.

Link: openwrt#15368
Signed-off-by: Robert Marko <robimarko@gmail.com>
@openwrt-bot openwrt-bot merged commit 4454361 into openwrt:main May 31, 2024
2 checks passed
@robimarko
Copy link
Contributor

Thanks! Rebased on top of main and merged!

@httpstorm
Copy link
Contributor

@mpratt14 Congratulations, and thanks for the hard work. 🍻

@mpratt14
Copy link
Contributor Author

now it's time to attack the size of the patch, phase 2 coming soon...

Vladdrako pushed a commit to Vladdrako/openwrt that referenced this pull request Jun 8, 2024
The gnulib fts header is meant to not be overwritten
in any way by the host system's copy of fts.h
and was therefore given a unique name instead.

This is fine if the built libgnu library is directly linked
with the target library, but if we want to keep them isolated
we end up having the definitions being mangled anyway
when the next object to link against included the fts.h header.

On some macOS platforms, the use of __DARWIN_INODE64
is messing with the link name for fts functions, resulting in:

Undefined symbols for architecture x86_64:
  "_rpl_fts_close$INODE64", referenced from:
...

Create a local fts header for gnulib
that completely blocks the macOS host fts header.

An alternative and more upstream friendly fix would be
to rename fts_.h to fts.h and add the macOS-only
include guard to that file within it's own include guard,
but that would be a massive patch, so do this for now.

Tested-by: Georgi Valkov <gvalkov@gmail.com> # macOS
Signed-off-by: Michael Pratt <mcpratt@pm.me>
Link: openwrt#15368
Signed-off-by: Robert Marko <robimarko@gmail.com>
Vladdrako pushed a commit to Vladdrako/openwrt that referenced this pull request Jun 8, 2024
Install binaries that are not common with binutils
instead of none at all. This adds a negligible time to the build.

Building shared libraries is disabled, so the AM_LDFLAGS can be reset
without the rpath-link option which is unrecognized by clang.

Some of the binaries depend on functions that are defined
using a "strong alias" instead of a normal definition,
but this is disabled by our patches in order to work on macOS,
so use the identical function directly instead.

Add fnmatch from gnulib with GNU extensions
which is needed for usage of the FNM_EXTMATCH flag.

Handle a "Wunused-const-variable" error with the same
preprocessor conditional used to include the function
that the variable is used in.

Ref: f64bd4b ("tools/elfutils: only build required components")
Tested-by: Georgi Valkov <gvalkov@gmail.com> # macOS
Signed-off-by: Michael Pratt <mcpratt@pm.me>
Link: openwrt#15368
Signed-off-by: Robert Marko <robimarko@gmail.com>
Vladdrako pushed a commit to Vladdrako/openwrt that referenced this pull request Jun 8, 2024
The compiled library resulting from importing gnulib has been
linked to libelf in order to easily cover other link dependencies.
However, this is not appropriate for linking libelf to other programs
as it bloats the resulting libelf library, and may result in
multiple defintions of symbols based on whether or not
certain modules from gnulib are included while elfutils
already has it's own definition of a function.

This is not a problem while building elfutils, because gnulib has
it's own way of creating function aliases and special declarations
that allow the linker to ignore the original function definitions,
however, when libelf is used to link to something else,
this results in an error at link time.

The gnulib manual recommended linking the libraries directly,
but those who have written it may not have considered how this
can affect the ability to link that library in other builds,
they likely assume the build targets would not be a dependency.

Fix this by removing the linking between gnulib and libelf
and instead overriding Make variables in order to add linking
between gnulib and each of the binaries provided by elfutils,
using Make functions to avoid applying it to other subdirectories.

The function tdestroy() would still be missing on macOS,
but the existence of the gnulib tsearch object having been built
is an indicator of whether or not it is needed
because it is only built conditionally by gnulib,
so include linking that object only when it exists.

Block the unnecessary replacement of some functions by gnulib
so that future linking with libelf doesn't require
the associated gnulib "rpl" prefixed functions.
These replacements are very strict in order to correct
minor bugs that don't have a real impact in almost all cases
or new standards requirements that are not yet in effect or used.

Tested-by: Georgi Valkov <gvalkov@gmail.com> # macOS
Signed-off-by: Michael Pratt <mcpratt@pm.me>
Link: openwrt#15368
Signed-off-by: Robert Marko <robimarko@gmail.com>
Vladdrako pushed a commit to Vladdrako/openwrt that referenced this pull request Jun 8, 2024
Trying to compile elfutils on Fedora 40 with GCC 14.1.1 will fail with:
/home/robimarko/Building/AX3600/qualcommax/staging_dir/host/bin/g++ -std=c++11 -D_GNU_SOURCE -DHAVE_CONFIG_H -DLOCALEDIR='"/home/robimarko/Building/AX3600/qualcommax/staging_dir/host/share/locale"'  -DDEBUGPRED=0 -DSRCDIR=\"/home/robimarko/Building/AX3600/qualcommax/build_dir/host/elfutils-0.191/src\" -DOBJDIR=\"/home/robimarko/Building/AX3600/qualcommax/build_dir/host/elfutils-0.191/src\" -I. -I..  -I../libgnu -I../libgnu -I. -I. -I../lib -I.. -I./../libelf -I./../libebl -I./../libdw -I./../libdwelf -I./../libdwfl -I./../libasm -I../debuginfod -I/home/robimarko/Building/AX3600/qualcommax/staging_dir/host/include  -std=c++11 -Wall -Wshadow -Wtrampolines -Wlogical-op -Wduplicated-cond -Wnull-dereference -Wimplicit-fallthrough=5 -Werror -Wunused -Wextra -Wstack-usage=262144   -D_FORTIFY_SOURCE=3  -c -o srcfiles.o srcfiles.cxx
In file included from /usr/include/c++/14/x86_64-redhat-linux/bits/os_defines.h:39,
                 from /usr/include/c++/14/x86_64-redhat-linux/bits/c++config.h:2521,
                 from /usr/include/c++/14/cstdlib:41,
                 from ../libgnu/gettext.h:56,
                 from ../libgnu/eu-config.h:62,
                 from ../config.h:2378,
                 from srcfiles.cxx:31:
/usr/include/features.h:414:4: error: #warning _FORTIFY_SOURCE requires compiling with optimization (-O) [-Werror=cpp]
  414 | #  warning _FORTIFY_SOURCE requires compiling with optimization (-O)
      |    ^~~~~~~
cc1plus: all warnings being treated as errors

So, lets do as the error says and pass -O2 in HOST_CXXFLAGS like we already
do by default in HOST_CFLAGS.

Link: openwrt#15368
Signed-off-by: Robert Marko <robimarko@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build/scripts/tools pull request/issues for build, scripts and tools related changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

frr: multiple definition of `xmalloc'
6 participants