Skip to content

naked functions: emit .private_extern on macos - #148339

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
folkertdev:naked-macos-private-extern
Jan 7, 2026
Merged

naked functions: emit .private_extern on macos#148339
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
folkertdev:naked-macos-private-extern

Conversation

@folkertdev

@folkertdevfolkertdev commented Oct 31, 2025

Copy link
Copy Markdown
Contributor

View all comments

fixes#148307

Emit .private_extern on macos when the naked function uses Linkage::Internal. Failing to do so can cause issues with LTO.

The documentation on this directive is kind of sparse, but I believe this is at least not incorrect, and does fix the issue.

r? @Amanieu
cc @bjorn3

@folkertdevfolkertdev added the A-naked Area: `#[naked]`, prologue and epilogue-free, functions, https://git.io/vAzzS label Oct 31, 2025
@rustbot

Copy link
Copy Markdown
Collaborator

Some changes occurred in compiler/rustc_codegen_ssa

cc @WaffleLapkin

@rustbotrustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 31, 2025
@bjorn3

Copy link
Copy Markdown
Member

Is this really only an issue on macOS? I would have assumes this is an issue on all platforms.

@folkertdev

Copy link
Copy Markdown
ContributorAuthor

The reproduction given in the issue builds successfully for me on linux.

I did just notice that we do already have

match item_data.visibility{
Visibility::Default | Visibility::Protected => {}
Visibility::Hidden => writeln!(begin,".private_extern {asm_name}").unwrap(),
}

That clearly did not actually trigger in this case. Is that right?

@bjorn3

Copy link
Copy Markdown
Member

Yeah, the issue here I believe is that rustc correctly computes the symbol visibility for the naked function as private, but then when ThinLTO decides to inline the caller of the naked function, it is unable to change the naked function to be public (+ add a .llvm.<somehash> suffix to the symbol name to prevent conflicts) like it would do for regular functions. So we have to mark all naked functions as visible within the same DSO rather than just within the same object file, aka use external linkage + hidden visibility on ELF and equivalent with other object file formats.

@folkertdev

Copy link
Copy Markdown
ContributorAuthor

aka use external linkage + hidden visibility on ELF and equivalent with other object file formats.

Hmm, we do emit the following:

// If the function is #[naked] or contains any other attribute that requires exactly-once
// instantiation:
// We emit an unused_attributes lint for this case, which should be kept in sync if possible.
let codegen_fn_attrs = tcx.codegen_instance_attrs(instance.def);
if codegen_fn_attrs.contains_extern_indicator()
|| codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::NAKED)
{
returnInstantiationMode::GloballyShared{may_conflict:false};
}

but apparently that is not enough.

Is compiler/rustc_monomorphize/src/partitioning.rs the right place to fix this?

@bjorn3

Copy link
Copy Markdown
Member

That gets overridden at

// If we got here, we did not find any uses from other CGUs, so
// it's fine to make this monomorphization internal.
data.linkage = Linkage::Internal;
data.visibility = Visibility::Default;

@folkertdev
folkertdevforce-pushed the naked-macos-private-extern branch from 502098d to d96ae8fCompareNovember 2, 2025 20:59
@rustbot

This comment has been minimized.

Comment on lines -184 to +185
// write nothing
// LTO can fail when internal linkage is used.
emit_fatal("naked functions may not have internal linkage")

@folkertdevfolkertdevNov 2, 2025

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this too strict? We could allow it, but I think this is only reachable now with an explicit linkage attribute (which is unstable).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine for now. We can always revise it later if it becomes a problem.

@Amanieu

Copy link
Copy Markdown
Member

I think the issue with inlining is bigger than that and we effectively have to always use global visibility for naked functions. Consider dylib crates where the naked function is private but is called by an inlinable function. If that function gets inlined into another crate then the naked function needs to have global visibility so that it can be referenced from another dylib.

@bjorn3

Copy link
Copy Markdown
Member

Consider dylib crates where the naked function is private but is called by an inlinable function. If that function gets inlined into another crate then the naked function needs to have global visibility so that it can be referenced from another dylib.

If rustc considers the caller to be cross-crate codegenable, it would already mark the callee as public be it a regular function be it a naked function. The problematic case is where the codegen backend decides to inline a function into another codegen unit when rustc didn't consider it cross-crate codegenable. This can only happen within a single dylib through ThinLTO, not between dylibs. And it is only an issue for naked functions as ThinLTO can't make the function public itself as it would do for regular functions.

@folkertdev

Copy link
Copy Markdown
ContributorAuthor

@Amanieu will you be able to review this? it is starting to block some things apparently.

@Amanieu

Copy link
Copy Markdown
Member

@bors r+

@bors

bors commented Jan 6, 2026

Copy link
Copy Markdown
Collaborator

📌 Commit d96ae8f has been approved by Amanieu

It is now in the queue for this repository.

@borsbors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 6, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jan 6, 2026
…ern, r=Amanieu
naked functions: emit `.private_extern` on macos
fixesrust-lang#148307
Emit `.private_extern` on macos when the naked function uses `Linkage::Internal`. Failing to do so can cause issues with LTO.
The documentation on this directive is kind of sparse, but I believe this is at least not incorrect, and does fix the issue.
r? `@Amanieu`
cc `@bjorn3`
bors added a commit that referenced this pull request Jan 6, 2026
…uwer
Rollup of 11 pull requests
Successful merges:
- #144113 (Impls and impl items inherit `dead_code` lint level of the corresponding traits and trait items)
- #148339 (naked functions: emit `.private_extern` on macos)
- #149880 (rustc_codegen_llvm: update alignment for double on AIX)
- #150122 (Refactor function names of `rustc_ast_lowering`)
- #150412 (use PIDFD_GET_INFO ioctl when available)
- #150670 (THIR pattern building: Move all `thir::Pat` creation into `rustc_mir_build::thir::pattern`)
- #150695 (MGCA: pretty printing for struct expressions and tuple calls )
- #150698 (Improve comment clarity in candidate_may_shadow)
- #150706 (Update wasm-component-ld)
- #150707 (Fix ICE when transmute Assume field is invalid)
- #150708 (Enable merge queue in new bors)
r? `@ghost`
`@rustbot` modify labels: rollup
@JonathanBrouwer

Copy link
Copy Markdown
Member

@bors r-
#150724 (comment)

@borsbors removed the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Jan 6, 2026
@rust-borsrust-borsBot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jan 6, 2026
@borsbors added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jan 6, 2026
bors added a commit that referenced this pull request Jan 6, 2026
Rollup of 11 pull requests
Successful merges:
- #144113 (Impls and impl items inherit `dead_code` lint level of the corresponding traits and trait items)
- #148339 (naked functions: emit `.private_extern` on macos)
- #149880 (rustc_codegen_llvm: update alignment for double on AIX)
- #150122 (Refactor function names of `rustc_ast_lowering`)
- #150412 (use PIDFD_GET_INFO ioctl when available)
- #150670 (THIR pattern building: Move all `thir::Pat` creation into `rustc_mir_build::thir::pattern`)
- #150695 (MGCA: pretty printing for struct expressions and tuple calls )
- #150698 (Improve comment clarity in candidate_may_shadow)
- #150706 (Update wasm-component-ld)
- #150707 (Fix ICE when transmute Assume field is invalid)
- #150708 (Enable merge queue in new bors)
r? `@ghost`
`@rustbot` modify labels: rollup
@Amanieu

Copy link
Copy Markdown
Member

ERROR: unknown compiletest directive add-core-stubs at /checkout/tests/assembly-llvm/naked-functions/hidden.rs:2

bors added a commit that referenced this pull request Jan 6, 2026
naked functions: emit `.private_extern` on macos
fixes#148307
Emit `.private_extern` on macos when the naked function uses `Linkage::Internal`. Failing to do so can cause issues with LTO.
The documentation on this directive is kind of sparse, but I believe this is at least not incorrect, and does fix the issue.
r? `@Amanieu`
cc `@bjorn3`
@bors

bors commented Jan 6, 2026

Copy link
Copy Markdown
Collaborator

⌛ Testing commit 76d0843 with merge 23720f5...

@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job dist-powerpc64-linux failed! Check out the build log: (web)(plain enhanced)(plain)

Click to see the possible cause of the failure (guessed by this bot)
[RUSTC-TIMING] rustc_driver_impl test:false 41.837
[RUSTC-TIMING] rustc_query_impl test:false 129.366
error: linking with `powerpc64-unknown-linux-gnu-gcc` failed: exit status: 1
|
= note: "powerpc64-unknown-linux-gnu-gcc" "-Wl,--version-script=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-rustc/powerpc64-unknown-linux-gnu/release/deps/rustcTNzRaV/list" "-Wl,--no-undefined-version" "-m64" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-rustc/powerpc64-unknown-linux-gnu/release/deps/rustcTNzRaV/symbols.o" "<1 object files omitted>" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-rustc/powerpc64-unknown-linux-gnu/release/deps/rustcTNzRaV/rmeta.o" "<1 object files omitted>" "-Wl,--as-needed" "-Wl,-Bstatic" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-rustc/powerpc64-unknown-linux-gnu/release/deps/{librustc_driver_impl-1ca3fffae45d6885,libctrlc-1ed45bc06e8d91d5,libnix-ffa2df428413fa28,librustc_log-53f6af51de046ee0,libtracing_tree-6dc1da0c0b43bc95,libtracing_log-bc5c2fd94504b575,libtracing_subscriber-32de6740c7683d37,libsharded_slab-036392b7ffdd48aa,liblazy_static-398abcdaa3500e3b,libmatchers-ac1ac5b4bd7b8945,libnu_ansi_term-1c0ba898e2eac9d6,libthread_local-06203d23089b77f3,libjiff-86a89b86de99ff6c,libshlex-9ec9cadb82e90b7a,librustc_public-f2deabc9703cede2,librustc_public_bridge-96a2790380fd6372,librustc_interface-449c2be593d3198c,librustc_codegen_llvm-8301e12a5e12121a,liblibloading-d92bd35db9d9af4e,librustc_llvm-eaab2b9836d77290,librustc_sanitizers-522c637ba3a9f4a1,librustc_hir_typeck-1e35737bb3bd87d0,librustc_hir_analysis-f576e8632f11d474,librustc_monomorphize-f9597d3f8a4e5e1f,librustc_mir_transform-078b2c6929a20903,librustc_mir_build-ffd68f2b4847a9c9,librustc_pattern_analysis-cd0510c255d867cd,librustc_borrowck-e5c9ebe3d184efed,librustc_traits-7303c20f13b065e7,librustc_const_eval-b5971a79583eb397,librustc_mir_dataflow-979d15fd0abf96d0,librustc_builtin_macros-5170a75602fa5443,librustc_resolve-90584c7d5b131c78,libpulldown_cmark-61fb84a95e7b2d5a,libunicase-2c02da88aabb629c,libpulldown_cmark_escape-3c2435480f4c1e71,librustc_passes-fbaec614cf2899ce,librustc_ast_lowering-31b4efba6b96eb41,librustc_privacy-7748cbff86a34d6f,librustc_ty_utils-68701bfbe77b868f,librustc_lint-7a6ddb8f0e87d0e1,libunicode_security-de40848893082aca,libunicode_script-6ca941414013b716,librustc_query_impl-9ef1770ca293374a,librustc_codegen_ssa-64b69b85d351332a,libwasm_encoder-2cfbe6276bdbc6a9,libleb128-f5d3648badd7d691,libthorin-95af3945c5dfa2f4,libgimli-3785c81ce4ba03cd,libfallible_iterator-e054e6d6813b5d9c,libobject-6fb8c03cd0645cd0,libruzstd-97950cb841498685,libtwox_hash-81319f46c315d7ec,librand-cdc890246e62aaf7,librand_chacha-c36f910d70af014c,librand_core-f62390199eb78666,libgetrandom-480fbdd41960578f,libstatic_assertions-b9eea94002e22776,libflate2-54037b770283b724,libminiz_oxide-7834a771cc528c7c,libsimd_adler32-c9b72bad6c27bad7,libbstr-f35422c2cdead16a,librustc_trait_selection-9b9a204b71d354eb,librustc_next_trait_solver-7442009f0d4810d6,librustc_parse_format-0479dc0511b34d99,librustc_transmute-8be5d959a7249eb0,librustc_infer-39b3e05623df9ee0,librustc_symbol_mangling-6c961405d25274a1,librustc_demangle-6ec389ae9215e30f,libpunycode-8e399b9a2b5c15be,libpathdiff-b0975aea3d06b843,libregex-a8479759fedfc720,libfind_msvc_tools-6bec644f23c77d27,libar_archive_writer-d4b07f50c1f7bb1d,librustc_metadata-880b269398fd5d5f,liblibloading-e27628bc7b3b6dd3,librustc_incremental-04989acd7fe5c0c6,librustc_expand-425ad223f9c9e055,librustc_ast_passes-17e65209e7e26683,librustc_proc_macro-5140ddf2906b8fb3,librustc_attr_parsing-e0646cb8bf3635ba,librustc_parse-b6e9cb851393b95d,libunicode_normalization-46c88a4a809d14e9,libtinyvec-440bcd5cdbc791e7,libtinyvec_macros-be3156db1e256b2d,librustc_middle-d020bc7590816ea1,librustc_apfloat-47b90db477578c47,libgsgdt-a5bba739e8dd7df9,libpolonius_engine-54d18695ffc881ec,libdatafrog-2013f67b245cc199,librustc_query_system-966911079a040042,librustc_type_ir-cc369d3dac50bf11,librustc_session-27e18a1d67d41d2d,libgetopts-281ea86a972745bb,librustc_feature-cd3c0960efdb8c22,librustc_hir_pretty-21ba4abb54871aaa,librustc_errors-5ebb27aaba5cb9e0,libtermize-dbfcc7c7c9b0694e,librustc_error_codes-88d58ae6da2c87d0,libannotate_snippets-b5b7b266eca12e97,libanstream-c60e097f81bef85d,libanstyle_query-e2b3ce2fcc77001f,libis_terminal_polyfill-20bbaf0714fa1f1f,libanstyle-a23a01041f5fc457,libcolorchoice-f61c09cbfcd53790,libanstyle_parse-acf81b25e103889e,libutf8parse-928a5da8b469ec21,librustc_hir-dafbe15f408f8ebf,libodht-bf0742ed96e22548,librustc_lint_defs-1715f90222b2c5be,librustc_hir_id-a87f118cb807297a,librustc_target-1d499adfb145048a,libserde_path_to_error-9fc4b10bf107e01f,libschemars-ec8ebfcfa3cefd0d,libdyn_clone-35776ddba6a965f1,libserde-7cdbe56c89dfba14,libref_cast-c82a4f9327501c68,libobject-b98f845c7189dbbb,libcrc32fast-78cf4d37c2bcab39,libwasmparser-d5c85680c3125356,librustc_fs_util-8d8aa55137d03eec,libserde_json-7ec699caa4c4f767,libryu-f81290dc2a4f3ebb,libserde_core-76d022db0aa6e5b0,librustc_abi-7695dfaceffc4a83,librand_xoshiro-7faf6b57928678a4,librustc_error_messages-e734c326af39c12d,librustc_baked_icu_data-d67eec5af65524e3,libicu_list-05fff01e7e21b902,libregex_automata-3e997478da401af6,libaho_corasick-23ec6b01378c284a,libregex_syntax-a282a0374869a508,libicu_locale-3f6997b1e81a1ebe,libicu_locale_data-730dc74e5dbb25e8,libicu_collections-20df45cd020d0447,libpotential_utf-c79cc2b60b456c99,libicu_provider-2a604cdef973d4f3,libzerotrie-4e1ddcff74a00615,libicu_locale_core-1480511ef94450d5,libwriteable-bf894792c8cd07ee,liblitemap-2df2c4d394c53b09,librustc_ast_pretty-1ef1183e525f5304,librustc_lexer-8a26bef46a277923,libunicode_properties-6ceefad04ef46043,libunicode_ident-63773cfe9f5ae01a,libitertools-7c95d80adaac05ca,libfluent_bundle-4d38beadb9cce8b8,libfluent_langneg-86647e20e404d986,libintl_pluralrules-db3f8dc1fcb67ede,libself_cell-4442509c19ecb901,libintl_memoizer-e2dca97882fa4563,libtype_map-857d666496df4d64,libunic_langid-69776655e1e45a13,libunic_langid_macros-c64a85104e0856f2,libunic_langid_impl-d213933363f0096f,libtinystr-09456d53ba8cf8eb,libzerovec-a21ac751f4f189ca,libyoke-8845442e6cb1cb99,libzerofrom-ca924cd500aa5ba0,libfluent_syntax-03c315051b0ae836,libthiserror-c508bda50478da91,librand-9798b848271bb639,librand_chacha-b9831ec5eb34f920,libppv_lite86-dd0fe2dfb05de3f7,libzerocopy-2d38c8042936429c,librand_core-9c0dbaf335269d60,librustc_ast-83a577f08171028c,libmemchr-adeda6ce0c5adc70,librustc_ast_ir-474c631650908e32,librustc_literal_escaper-b35cdda04a3ec47d,librustc_span-c5208dae11be2676,libblake3-a6dd4f72cbecb8f5,libconstant_time_eq-f20f16f4eac33d64,libarrayref-ccb4e6117c89c30d,libitoa-fbbf757fb35bd565,libscoped_tls-098d766eef0ee684,libsha2-2c52f68962a76dc4,libsha1-8c855e8b58f8762e,libmd5-434ebb8fb1aed5db,libdigest-8d50f211a52fa3c0,libblock_buffer-748faa0ae196783c,libcrypto_common-589c86fccf05c961,libgeneric_array-7205cf6abe51bf47,libtypenum-9f2f6e2a19100b03,libunicode_width-c60ad6f8b57a7d34,librustc_data_structures-be2eb2acee1beb64,libelsa-8218bf057fbb448e,libstable_deref_trait-18fea44cced7728c,librustc_thread_pool-cca3c1d73bf1972f,libcrossbeam_deque-991d1a7e98596df8,libcrossbeam_epoch-fa082b2de3a3ed7f,libcrossbeam_utils-33f755f7eedfa5b5,libstacker-f8b85902b3668fd2,libpsm-cc13653f391de9b6,libmemmap2-fae3f2cde9e6248c,librustc_arena-10c7f105e3804f65,libtempfile-daa8514489925450,libgetrandom-4086a72d245f0332,libfastrand-861e666a9e326019,librustix-43a31de1fcd923bb,liblinux_raw_sys-4f57a821dc54769e,libbitflags-0a7917c053d0e5d7,liberrno-69b412ec76b9ba1a,libarrayvec-4142eadaae87c33f,libhashbrown-d965c60aa98a1c71,libfoldhash-be81e97bc4dd79a5,libmeasureme-1edd9763c1e9dc28,librustc_hash-655049ab0fda8567,librustc_graphviz-bcf042f9824985f1,libparking_lot-d990a143fafa6503,libparking_lot_core-751e255f6f5489ca,libcfg_if-1c4c4e63f27d7e64,liblock_api-7480bab1b37215d6,libscopeguard-96a2aff9c9839bda,libjobserver-e0d15817746cc067,liblibc-7d3dedb0a8892ed5,libtracing-9291cc74c1a5f8e7,libpin_project_lite-ebc925a44d9b75b4,libtracing_core-93eb60c6c8f6e1f5,libonce_cell-dfbd8833fc2d1a7b,librustc_hash-ada8c2f9dbab51e7,libeither-aa64fe7e401abb06,librustc_index-fc84c573c496fea2,librustc_serialize-48a1875aba8913e8,libindexmap-3db519e4f5caa364,libequivalent-4bb4f89e60ce3eba,libhashbrown-e8d83cb5597e830e,libthin_vec-99321251f62d1cd0,librustc_hashes-165da186c45abc63,librustc_stable_hash-e4a3a31e3865fc72,libsmallvec-bee7681e127baff1,libena-447bf7bf72d87114,liblog-6eed0f03d029092f}.rlib" "<sysroot>/lib/rustlib/powerpc64-unknown-linux-gnu/lib/{libstd-*,libpanic_unwind-*,libobject-*,libmemchr-*,libaddr2line-*,libgimli-*,libcfg_if-*,librustc_demangle-*,libstd_detect-*,libhashbrown-*,librustc_std_workspace_alloc-*,libminiz_oxide-*,libadler2-*,libunwind-*,liblibc-*,librustc_std_workspace_core-*,liballoc-*,libcore-*,libcompiler_builtins-*}.rlib" "-Wl,-Bdynamic" "-ldl" "-ldl" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-rustc/powerpc64-unknown-linux-gnu/release/deps/rustcTNzRaV/raw-dylibs" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-rustc/powerpc64-unknown-linux-gnu/release/build/psm-018b79a1943a9aa9/out" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-rustc/powerpc64-unknown-linux-gnu/release/build/rustc_llvm-c8668ae673789711/out" "-L" "/checkout/obj/build/powerpc64-unknown-linux-gnu/llvm/lib" "-L" "/x-tools/powerpc64-unknown-linux-gnu/lib/gcc/powerpc64-unknown-linux-gnu/8.5.0/../../../../powerpc64-unknown-linux-gnu/lib/../lib64" "-L" "<sysroot>/lib/rustlib/powerpc64-unknown-linux-gnu/lib" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-rustc/powerpc64-unknown-linux-gnu/release/deps/librustc_driver-8987a4d9fd0f20fe.so" "-shared" "-Wl,-soname=librustc_driver-8987a4d9fd0f20fe.so" "-Wl,-z,relro,-z,now" "-Wl,-O1" "-nodefaultlibs" "-Wl,-z,origin" "-Wl,-rpath,$ORIGIN/../lib"
= note: some arguments are omitted. use `--verbose` to show all linker arguments
= note: /x-tools/powerpc64-unknown-linux-gnu/lib/gcc/powerpc64-unknown-linux-gnu/8.5.0/../../../../powerpc64-unknown-linux-gnu/bin/ld: BFD (crosstool-NG UNKNOWN) 2.32 assertion fail /tmp/build/.build/powerpc64-unknown-linux-gnu/src/binutils/bfd/elf64-ppc.c:10251
/x-tools/powerpc64-unknown-linux-gnu/lib/gcc/powerpc64-unknown-linux-gnu/8.5.0/../../../../powerpc64-unknown-linux-gnu/bin/ld: BFD (crosstool-NG UNKNOWN) 2.32 assertion fail /tmp/build/.build/powerpc64-unknown-linux-gnu/src/binutils/bfd/elf64-ppc.c:10251
collect2: error: ld returned 1 exit status
[RUSTC-TIMING] rustc_driver test:false 20.623
error: could not compile `rustc_driver` (lib) due to 1 previous error

@bors

bors commented Jan 6, 2026

Copy link
Copy Markdown
Collaborator

💔 Test failed - checks-actions

@borsbors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jan 6, 2026
@folkertdev

Copy link
Copy Markdown
ContributorAuthor

Hmm, this PR makes changes for macos only, so I'd guess this is a spurious failure?

@folkertdev

Copy link
Copy Markdown
ContributorAuthor

@bors2 try job=dist-powerpc64-linux

@rust-bors

rust-borsBot commented Jan 6, 2026

Copy link
Copy Markdown
Contributor

Unknown command "2". Run @bors help to see available commands.

@rust-bors

This comment has been minimized.

rust-borsBot added a commit that referenced this pull request Jan 6, 2026
naked functions: emit `.private_extern` on macos
try-job: dist-powerpc64-linux
@rust-bors

rust-borsBot commented Jan 6, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: fb973ae (fb973ae9e7b77ae1dcb9c74b5a434f44a8a4c2c9, parent: 4d73a008eaf6ba3ca067a3221e5c00602e33a5f2)

@folkertdev

Copy link
Copy Markdown
ContributorAuthor

@bors r=Amanieu

@bors

bors commented Jan 6, 2026

Copy link
Copy Markdown
Collaborator

💡 This pull request was already approved, no need to approve it again.

@bors

bors commented Jan 6, 2026

Copy link
Copy Markdown
Collaborator

📌 Commit 76d0843 has been approved by Amanieu

It is now in the queue for this repository.

@borsbors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 6, 2026
@rust-bors

This comment has been minimized.

@rust-borsrust-borsBot added the merged-by-bors This PR was explicitly merged by bors. label Jan 7, 2026
@rust-bors

rust-borsBot commented Jan 7, 2026

Copy link
Copy Markdown
Contributor

☀️ Test successful - CI
Approved by: Amanieu
Pushing fecb335 to main...

@rust-bors
rust-borsBot merged commit fecb335 into rust-lang:mainJan 7, 2026
13 of 14 checks passed
@rustbotrustbot added this to the 1.94.0 milestone Jan 7, 2026
@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

A job failed! Check out the build log: (web)(plain enhanced)(plain)

Click to see the possible cause of the failure (guessed by this bot)
 Running `target/release/citool post-merge-report fecb335cbad3d84ef3da39191ba094e6c726a5b4`
error: the following required arguments were not provided:
<CURRENT>
Usage: citool post-merge-report <PARENT> <CURRENT>
For more information, try '--help'.
##[error]Process completed with exit code 2.
Post job cleanup.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (fecb335): comparison URL.

Overall result: ✅ improvements - no action needed

@rustbot label: -perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

meanrangecount
Regressions ❌
(primary)
--0
Regressions ❌
(secondary)
--0
Improvements ✅
(primary)
--0
Improvements ✅
(secondary)
-0.0%[-0.0%, -0.0%]1
All ❌✅ (primary)--0

Max RSS (memory usage)

Results (primary 1.5%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

meanrangecount
Regressions ❌
(primary)
1.5%[1.5%, 1.5%]1
Regressions ❌
(secondary)
--0
Improvements ✅
(primary)
--0
Improvements ✅
(secondary)
--0
All ❌✅ (primary)1.5%[1.5%, 1.5%]1

Cycles

Results (secondary 3.0%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

meanrangecount
Regressions ❌
(primary)
--0
Regressions ❌
(secondary)
3.0%[3.0%, 3.0%]1
Improvements ✅
(primary)
--0
Improvements ✅
(secondary)
--0
All ❌✅ (primary)--0

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 487.524s -> 473.64s (-2.85%)
Artifact size: 390.86 MiB -> 390.86 MiB (0.00%)

Comment on lines +583 to +591
// When LTO inlines the caller of a naked function, it will attempt but fail to make the
// naked function symbol visible. To ensure that LTO works correctly, do not default
// naked functions to internal linkage and default visibility.
if let MonoItem::Fn(instance) = item {
let flags = cx.tcx.codegen_instance_attrs(instance.def).flags;
if flags.contains(CodegenFnAttrFlags::NAKED) {
continue;
}
}

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bjorn3 why would we handle naked functions differently from some other external symbol defined in global assembly?

extern"C"{fnfoo();}global_asm!("foo:","ret");

is it just that nobody ran into this issue with global assembly so far? In any case this fix is causing issues elsewhere, see #151946

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

global_asm!("foo:","ret");

this defines a local symbol, which means that only if foo gets called within the exact same object file will it work. There is never a guarantee that the global_asm!() gets added to the same codegen unit, so without .globl foo or (if you don't use dylibs) .hidden foo your example is effectively invalid.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-nakedArea: `#[naked]`, prologue and epilogue-free, functions, https://git.io/vAzzSF-naked_functions`#![feature(naked_functions)]`merged-by-borsThis PR was explicitly merged by bors.S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to link code containing naked functions on ARM64 macOS with ThinLTO enabled

9 participants

@folkertdev@rustbot@bjorn3@Amanieu@bors@JonathanBrouwer@matthiaskrgr@rust-log-analyzer@rust-timer