@@ -383,15 +383,43 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant
383
383
384
384
if let Some ( section_name) = section_name {
385
385
let ( segment_name, section_name) = if tcx. sess . target . is_like_osx {
386
- let section_name = section_name. as_str ( ) ;
387
- if let Some ( names) = section_name. split_once ( ',' ) {
388
- names
389
- } else {
386
+ // See https://github.com/llvm/llvm-project/blob/main/llvm/lib/MC/MCSectionMachO.cpp
387
+ let mut parts = section_name. as_str ( ) . split ( ',' ) ;
388
+ let Some ( segment_name) = parts. next ( ) else {
390
389
tcx. dcx ( ) . fatal ( format ! (
391
390
"#[link_section = \" {}\" ] is not valid for macos target: must be segment and section separated by comma" ,
392
391
section_name
393
392
) ) ;
393
+ } ;
394
+ let Some ( section_name) = parts. next ( ) else {
395
+ tcx. dcx ( ) . fatal ( format ! (
396
+ "#[link_section = \" {}\" ] is not valid for macos target: must be segment and section separated by comma" ,
397
+ section_name
398
+ ) ) ;
399
+ } ;
400
+ if section_name. len ( ) > 16 {
401
+ tcx. dcx ( ) . fatal ( format ! (
402
+ "#[link_section = \" {}\" ] is not valid for macos target: section name bigger than 16 bytes" ,
403
+ section_name
404
+ ) ) ;
405
+ }
406
+ let section_type = parts. next ( ) . unwrap_or ( "regular" ) ;
407
+ if section_type != "regular" && section_type != "cstring_literals" {
408
+ tcx. dcx ( ) . fatal ( format ! (
409
+ "#[link_section = \" {}\" ] is not supported: unsupported section type {}" ,
410
+ section_name, section_type,
411
+ ) ) ;
412
+ }
413
+ let _attrs = parts. next ( ) ;
414
+ if parts. next ( ) . is_some ( ) {
415
+ tcx. dcx ( ) . fatal ( format ! (
416
+ "#[link_section = \" {}\" ] is not valid for macos target: too many components" ,
417
+ section_name
418
+ ) ) ;
394
419
}
420
+ // FIXME(bytecodealliance/wasmtime#8901) set S_CSTRING_LITERALS section type when
421
+ // cstring_literals is specified
422
+ ( segment_name, section_name)
395
423
} else {
396
424
( "" , section_name. as_str ( ) )
397
425
} ;
0 commit comments