| 
									
										
										
										
											2020-10-10 14:16:11 +02:00
										 |  |  | # typed: true | 
					
						
							| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-08 20:06:09 +01:00
										 |  |  | require "compilers" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-05 15:29:42 -07:00
										 |  |  | class LinkageChecker | 
					
						
							|  |  |  |   # Libraries provided by glibc and gcc. | 
					
						
							| 
									
										
										
										
											2020-06-06 19:12:12 +01:00
										 |  |  |   SYSTEM_LIBRARY_ALLOWLIST = %w[
 | 
					
						
							| 
									
										
										
										
											2018-09-05 15:29:42 -07:00
										 |  |  |     ld-linux-x86-64.so.2
 | 
					
						
							| 
									
										
										
										
											2022-09-29 16:33:44 +08:00
										 |  |  |     ld-linux-aarch64.so.1
 | 
					
						
							| 
									
										
										
										
											2018-09-05 15:29:42 -07:00
										 |  |  |     libanl.so.1
 | 
					
						
							| 
									
										
										
										
											2021-05-31 00:40:19 -07:00
										 |  |  |     libatomic.so.1
 | 
					
						
							| 
									
										
										
										
											2018-09-05 15:29:42 -07:00
										 |  |  |     libc.so.6
 | 
					
						
							|  |  |  |     libdl.so.2
 | 
					
						
							|  |  |  |     libm.so.6
 | 
					
						
							|  |  |  |     libmvec.so.1
 | 
					
						
							|  |  |  |     libnsl.so.1
 | 
					
						
							| 
									
										
										
										
											2021-12-31 16:17:36 -08:00
										 |  |  |     libnss_files.so.2
 | 
					
						
							| 
									
										
										
										
											2018-09-05 15:29:42 -07:00
										 |  |  |     libpthread.so.0
 | 
					
						
							|  |  |  |     libresolv.so.2
 | 
					
						
							|  |  |  |     librt.so.1
 | 
					
						
							| 
									
										
										
										
											2019-12-05 21:44:07 +01:00
										 |  |  |     libthread_db.so.1
 | 
					
						
							| 
									
										
										
										
											2018-09-05 15:29:42 -07:00
										 |  |  |     libutil.so.1
 | 
					
						
							|  |  |  |     libgcc_s.so.1
 | 
					
						
							|  |  |  |     libgomp.so.1
 | 
					
						
							|  |  |  |     libstdc++.so.6
 | 
					
						
							|  |  |  |   ].freeze | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-15 20:37:32 +01:00
										 |  |  |   def display_deprecated_warning(strict: false) | 
					
						
							| 
									
										
										
										
											2022-08-23 09:55:30 +01:00
										 |  |  |     # Steps when moving these to `odisabled`: | 
					
						
							|  |  |  |     # - Remove the old library from SYSTEM_LIBRARY_ALLOWLIST above. | 
					
						
							|  |  |  |     # - Remove the `disable` and `disable_for_developer` kwargs here. | 
					
						
							|  |  |  |     # - Adjust the `broken_library_linkage?` override below to not check for the library. | 
					
						
							|  |  |  |     # - Remove the relevant `fail_on_lib*?`. | 
					
						
							|  |  |  |     # If there's no more deprecations left: | 
					
						
							|  |  |  |     # - Remove the `broken_library_linkage?` override and the generic alias in HOMEBREW_LIBRARY/linkage_checker.rb. | 
					
						
							|  |  |  |     # | 
					
						
							|  |  |  |     # Steps when removing handling for a library entirely (assuming the steps to `odisabled` has already been done): | 
					
						
							|  |  |  |     # - Remove the relevant setting of `@lib*_found` in `check_dylibs` below. | 
					
						
							|  |  |  |     # - Remove the `odisabled` line | 
					
						
							|  |  |  |     # If there's no library deprecated/disabled handling left: | 
					
						
							| 
									
										
										
										
											2022-04-15 20:37:32 +01:00
										 |  |  |     # - Remove the `display_` overrides here and the associated generic aliases in HOMEBREW_LIBRARY/linkage_checker.rb | 
					
						
							| 
									
										
										
										
											2022-08-23 09:55:30 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     odisabled "linkage to libcrypt.so.1", "libcrypt.so.2 in the libxcrypt formula" if @libcrypt_found | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return unless @libnsl_found | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     odeprecated "linkage to libnsl.so.1", "libnsl.so.3 in the libnsl formula", | 
					
						
							|  |  |  |                 disable:                fail_on_libnsl1?(strict: strict), | 
					
						
							|  |  |  |                 disable_for_developers: false | 
					
						
							| 
									
										
										
										
											2022-04-15 20:37:32 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def display_normal_output | 
					
						
							|  |  |  |     generic_display_normal_output | 
					
						
							|  |  |  |     display_deprecated_warning | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def display_test_output(puts_output: true, strict: false) | 
					
						
							|  |  |  |     generic_display_test_output(puts_output: puts_output, strict: strict) | 
					
						
							|  |  |  |     display_deprecated_warning(strict: strict) | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-23 09:38:52 +01:00
										 |  |  |   def broken_library_linkage?(test: false, strict: false) | 
					
						
							| 
									
										
										
										
											2022-08-23 09:55:30 +01:00
										 |  |  |     generic_broken_library_linkage?(test: test, strict: strict) || (fail_on_libnsl1?(strict: strict) && @libnsl_found) | 
					
						
							| 
									
										
										
										
											2022-04-15 20:37:32 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-23 09:55:30 +01:00
										 |  |  |   def fail_on_libnsl1?(strict:) | 
					
						
							|  |  |  |     strict || ENV["HOMEBREW_DISALLOW_LIBNSL1"].present? | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-05 15:29:42 -07:00
										 |  |  |   def check_dylibs(rebuild_cache:) | 
					
						
							|  |  |  |     generic_check_dylibs(rebuild_cache: rebuild_cache) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-15 20:37:32 +01:00
										 |  |  |     @libcrypt_found = true if @system_dylibs.any? { |s| File.basename(s) == "libcrypt.so.1" } | 
					
						
							| 
									
										
										
										
											2022-08-23 09:55:30 +01:00
										 |  |  |     @libnsl_found = true if @system_dylibs.any? { |s| File.basename(s) == "libnsl.so.1" } | 
					
						
							| 
									
										
										
										
											2022-04-15 20:37:32 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-05 15:29:42 -07:00
										 |  |  |     # glibc and gcc are implicit dependencies. | 
					
						
							|  |  |  |     # No other linkage to system libraries is expected or desired. | 
					
						
							|  |  |  |     @unwanted_system_dylibs = @system_dylibs.reject do |s| | 
					
						
							| 
									
										
										
										
											2020-06-06 19:12:12 +01:00
										 |  |  |       SYSTEM_LIBRARY_ALLOWLIST.include? File.basename(s) | 
					
						
							| 
									
										
										
										
											2018-09-05 15:29:42 -07:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2022-09-02 14:28:07 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-02 22:03:22 +08:00
										 |  |  |     # We build all formulae with an RPATH that includes the gcc formula's runtime lib directory. | 
					
						
							|  |  |  |     # See: https://github.com/Homebrew/brew/blob/e689cc07/Library/Homebrew/extend/os/linux/extend/ENV/super.rb#L53 | 
					
						
							|  |  |  |     # This results in formulae showing linkage with gcc whenever it is installed, even if no dependency is declared. | 
					
						
							|  |  |  |     # See discussions at: | 
					
						
							|  |  |  |     #   https://github.com/Homebrew/brew/pull/13659 | 
					
						
							|  |  |  |     #   https://github.com/Homebrew/brew/pull/13796 | 
					
						
							|  |  |  |     # TODO: Find a nicer way to handle this. (e.g. examining the ELF file to determine the required libstdc++.) | 
					
						
							| 
									
										
										
										
											2022-09-02 14:28:07 +08:00
										 |  |  |     @undeclared_deps.delete("gcc") | 
					
						
							| 
									
										
										
										
											2018-09-05 15:29:42 -07:00
										 |  |  |   end | 
					
						
							|  |  |  | end |