[llvm-bugs] [Bug 49090] New: Clang on Windows with "--target=x86_64-elf " seems to compile with "-ffunction-sections"

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Feb 8 08:04:24 PST 2021


https://bugs.llvm.org/show_bug.cgi?id=49090

            Bug ID: 49090
           Summary: Clang on Windows with "--target=x86_64-elf " seems to
                    compile with "-ffunction-sections"
           Product: clang
           Version: 11.0
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++2a
          Assignee: unassignedclangbugs at nondot.org
          Reporter: rianquinn at gmail.com
                CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
                    llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk

For some reason, when you cross compiler for "--target=x86_64-elf" on Windows
using Clang 11, and then link using ld.lld on Windows, you get an ELF file that
appears to have "-ffunction-sections" turned on, even though I have not turned
it on. In fact, if I turn it off, nothing changes. 

Here is an example:
```
[/c/working/build/ext_cross_compile/bin]: llvm-readelf.exe -lW example_default 

Elf file type is EXEC (Executable file)
Entry point 0x328000000c80
There are 4 program headers, starting at offset 64

Program Headers:
  Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz
  Flg Align
  LOAD           0x001000 0x0000328000000000 0x0000328000000000 0x007228
0x007228 R E 0x1000
  LOAD           0x009000 0x0000328000008000 0x0000328000008000 0x0004f0
0x0004f0 R   0x1000
  LOAD           0x00a000 0x0000328000009000 0x0000328000009000 0x000008
0x000010 RW  0x1000
  GNU_STACK      0x000000 0x0000000000000000 0x0000000000000000 0x000000
0x000000 RW  0x0

 Section to Segment mapping:
  Segment Sections...
   00     .text
.text._ZN7example6vmexitIN7syscall11bf_handle_tEEEvRT_RKN3bsl13safe_integralItEERKNS6_ImEE
.text._ZN3bsl13safe_integralItEC2ItLb1EEET_
.text._ZN3bsl13safe_integralImEC2ImLb1EEET_
.text._ZN3bsllsINS_7details14out_type_printEEENS_3outIT_EES5_RKNS_15source_locationE
.text._ZN3bsl5printILm1EEENS_11conditionalIXsr11disjunctionINS_17integral_constantIbXltT_scmL_ZNS_L1VEEEEENS2_IbXeqT_L_ZNS_L1VEEEEEEE5valueENS_3outINS_7details14out_type_printEEENS5_INS6_14out_type_emptyEEEE4typeEv
.text._ZN3bsl4hereENS_15source_locationE
.text._ZN3bsl15source_location7currentEPKcS2_j
.text._ZN7syscall18bf_control_op_exitEv .text._ZN3bsl7discardIJRKmEEEvDpOT_
.text._ZN3bsl13safe_integralItEC2Ev .text._ZN3bsl13safe_integralImEC2Ev
.text._ZN7syscall30bf_callback_op_register_vmexitERKNS_11bf_handle_tEPFvtmE
.text._ZN3bsl8unlikelyIbEEbOT_ .text._ZN3bslneImEEbRKNS_13safe_integralIT_EES5_
.text._ZN7syscall28bf_callback_op_register_failERKNS_11bf_handle_tEPFvmE
.text._ZN3bsleqItEEbRKNS_13safe_integralIT_EES2_
.text._ZN7syscall18bf_vm_op_create_vmERKNS_11bf_handle_tERN3bsl13safe_integralItEE
.text._ZN7syscall18bf_vp_op_create_vpERKNS_11bf_handle_tERN3bsl13safe_integralItEE
.text._ZN7syscall20bf_vps_op_create_vpsERKNS_11bf_handle_tERN3bsl13safe_integralItEE
.text._ZN7syscall22bf_vps_op_init_as_rootERKNS_11bf_handle_tERKN3bsl13safe_integralItEE
.text._ZN7example8init_vpsIN7syscall11bf_handle_tEEEN3bsl15basic_errc_typeIiEERT_RKNS3_13safe_integralItEE
.text._ZNK3bsl15basic_errc_typeIiEcvbEv
.text._ZN3bsl7discardIJNS_13safe_integralImEEEEEvDpOT_
.text._ZN7syscall13bf_vps_op_runERKNS_11bf_handle_tERKN3bsl13safe_integralItEES7_S7_
.text._ZN7syscall21bf_is_spec1_supportedERKN3bsl13safe_integralIjEE
.text._ZN3bsllsINS_7details14out_type_errorEEENS_3outIT_EES5_RKNS_15source_locationE
.text._ZN3bsllsINS_7details14out_type_errorEEENS_3outIT_EES5_PKc
.text._ZN3bsl5errorEv
.text._ZN7syscall24bf_handle_op_open_handleERKN3bsl13safe_integralIjEERNS_11bf_handle_tE
.text._ZN7syscall33bf_callback_op_register_bootstrapERKNS_11bf_handle_tEPFvtE
.text._ZN7syscall19bf_callback_op_waitEv .text._ZN3bsl15basic_errc_typeIiEC2Ev
.text._ZNK3bsl13safe_integralImE3getEv
.text._ZN7example19handle_vmexit_cpuidIN7syscall11bf_handle_tEEEN3bsl15basic_errc_typeIiEERT_RKNS3_13safe_integralItEE
.text._ZN7syscall36bf_vps_op_advance_ip_and_run_currentERKNS_11bf_handle_tE
.text._ZN3bsllsINS_7details14out_type_errorEEENS_3outIT_EES5_c
.text._ZN3bsllsINS_7details14out_type_errorENS_13safe_integralImEEEENS_3outIT_EES7_ONS_3fmtIT0_EE
.text._ZN3bsl3hexERKNS_13safe_integralImEE .text._ZN3bsl8unlikelyIRKbEEbOT_
.text._ZN7syscall10bf_tls_raxERKNS_11bf_handle_tE
.text._ZN7syscall10bf_tls_rbxERKNS_11bf_handle_tE
.text._ZN7syscall10bf_tls_rcxERKNS_11bf_handle_tE
.text._ZN7syscall10bf_tls_rdxERKNS_11bf_handle_tE
.text._ZN3bsleqIjEEbRKNS_13safe_integralIT_EES5_
.text._ZN3bsl13to_u32_unsafeImEENS_13safe_integralIjEERKNS1_IT_EE
.text._ZNK3bsl13safe_integralIjE3getEv
.text._ZN7syscall14bf_tls_set_raxERKNS_11bf_handle_tERKN3bsl13safe_integralImEE
.text._ZN7syscall20bf_vps_op_advance_ipERKNS_11bf_handle_tERKN3bsl13safe_integralItEE
.text._ZN7syscall17bf_vps_op_promoteERKNS_11bf_handle_tERKN3bsl13safe_integralItEE
.text._ZN3bsllsINS_7details14out_type_debugEEENS_3outIT_EES5_PKc
.text._ZN3bsl5debugILm0EEENS_11conditionalIXsr11disjunctionINS_17integral_constantIbXltT_scmL_ZNS_L1VEEEEENS2_IbXeqT_L_ZNS_L1VEEEEEEE5valueENS_3outINS_7details14out_type_debugEEENS5_INS6_14out_type_emptyEEEE4typeEv
.text._ZN3bsl5touchEv .text._ZN3bsl13safe_integralImE4dataEv
.text._ZN7syscall14bf_tls_set_rbxERKNS_11bf_handle_tERKN3bsl13safe_integralImEE
.text._ZN7syscall14bf_tls_set_rcxERKNS_11bf_handle_tERKN3bsl13safe_integralImEE
.text._ZN7syscall14bf_tls_set_rdxERKNS_11bf_handle_tERKN3bsl13safe_integralImEE
.text._ZN3bsl7discardIJRKN7syscall11bf_handle_tEEEEvDpOT_
.text._ZNK3bsl13safe_integralIjE7failureEv
.text._ZN3bsl13safe_integralIjEC2IjLb1EEET_
.text._ZNK3bsl13safe_integralItE3getEv
.text._ZN3bsl3outINS_7details14out_type_debugEE5writeEPKc
.text._ZN3bsl7details11puts_stdoutEPKc .text._ZN3bsl5fputsEPKc
.text._ZN7syscall21bf_debug_op_write_strEPKc
.text._ZN3bsl7details15print_thread_idINS0_14out_type_debugEEEvNS_3outIT_EE
.text._ZN7syscall16bf_tls_thread_idEv
.text._ZN3bsllsINS_7details14out_type_debugEEENS_3outIT_EES5_c
.text._ZN3bsllsINS_7details14out_type_debugENS_13safe_integralImEEEENS_3outIT_EES7_ONS_3fmtIT0_EE
.text._ZN3bsl3fmtINS_13safe_integralImEEEC2EPKcRKS2_
.text._ZN3bsl3outINS_7details14out_type_debugEE5writeEc
.text._ZN3bsl7details11putc_stdoutEc .text._ZN3bsl5fputcEc
.text._ZN7syscall19bf_debug_op_write_cEc
.text._ZN3bsl8fmt_implIRKNS_3outINS_7details14out_type_debugEEEmEEvOT_RKNS_11fmt_optionsERKNS_13safe_integralIT0_EE
.text._ZNK3bsl13safe_integralImEcvbEv
.text._ZN3bsl7details18fmt_impl_align_preINS_3outINS0_14out_type_debugEEEEENS_13safe_integralImEERKT_RKNS_11fmt_optionsERKS6_b
.text._ZN3bsl7details18fmt_impl_align_sufINS_3outINS0_14out_type_debugEEEEEvRKT_RKNS_11fmt_optionsERKNS_13safe_integralImEEb
.text._ZNK3bsl11fmt_options4typeEv
.text._ZN3bsl7details17fmt_impl_integralIRKNS_3outINS0_14out_type_debugEEEmEEvOT_RKNS_11fmt_optionsERKNS_13safe_integralIT0_EE
.text._ZN3bsl7forwardIRKNS_3outINS_7details14out_type_debugEEEEEOT_RNS_16remove_referenceIS7_E4typeE
.text._ZN3bsl13safe_integralImE3oneEb
.text._ZN3bslltImEEbRKNS_13safe_integralIT_EES5_
.text._ZNK3bsl11fmt_options5widthEv
.text._ZN3bslmiImEENS_13safe_integralIT_EERKS3_S5_
.text._ZN3bsl7to_umaxIiEENS_13safe_integralImEET_
.text._ZNK3bsl11fmt_options10sign_awareEv .text._ZNK3bsl11fmt_options5alignEv
.text._ZN3bslrsImEENS_13safe_integralIT_EERKS3_S5_
.text._ZNK3bsl11fmt_options4fillEv .text._ZNR3bsl13safe_integralImEppEv
.text._ZNK3bsl13safe_integralImE7failureEv
.text._ZNR3bsl13safe_integralImEmIERKS1_
.text._ZN3bsl20builtin_sub_overflowImEEbT_S1_PS1_
.text._ZN3bsl38integral_overflow_underflow_wrap_errorEv
.text._ZN3bsl7convertImiEENS_13safe_integralIT_EERKT0_
.text._ZN3bsl52conversion_failure_narrowing_results_in_loss_of_dataEv
.text._ZN3bsl13safe_integralImE4zeroEb
.text._ZN3bsl13safe_integralImEC2ImLb1EEET_b
.text._ZNR3bsl13safe_integralImErSERKS1_
.text._ZNR3bsl13safe_integralImEpLERKS1_
.text._ZN3bsl20builtin_add_overflowImEEbT_S1_PS1_
.text._ZN3bsl7details17get_integral_infoImEENS0_22fmt_impl_integral_infoIT_EERKNS_11fmt_optionsENS_13safe_integralIS3_EE
.text._ZN3bslplImEENS_13safe_integralIT_EERKS3_S5_
.text._ZNK3bsl11fmt_options14alternate_formEv
.text._ZNK3bsl13safe_integralImE7is_zeroEv
.text._ZNK3bsl13safe_integralImE6is_posEv
.text._ZNKR3bsl7details6carrayIcLm64EE5at_ifERKNS_13safe_integralImEE
.text._ZNR3bsl13safe_integralImEmmEv .text._ZNK3bsl11fmt_options4signEv
.text._ZN3bslrmImEENS_13safe_integralIT_EERKS3_S5_
.text._ZNR3bsl13safe_integralImEdVERKS1_
.text._ZN3bslgtImEEbRKNS_13safe_integralIT_EES5_
.text._ZN3bsl7convertImcEENS_13safe_integralIT_EERKT0_
.text._ZNR3bsl7details6carrayIcLm64EE5at_ifERKNS_13safe_integralImEE
.text._ZNR3bsl13safe_integralImErMERKS1_
.text._ZN3bsl20builtin_mod_overflowImEEbT_S1_PS1_
.text._ZN3bsl20builtin_div_overflowImEEbT_S1_PS1_
.text._ZN3bslltImEEbRKNS_13safe_integralIT_EES2_
.text._ZN3bsleqImEEbRKNS_13safe_integralIT_EES5_
.text._ZN3bsl11fmt_optionsC2EPKc
.text._ZN3bsl3fmtINS_13safe_integralImEEEC2ERKNS_11fmt_optionsERKS2_
.text._ZN3bsl14builtin_strlenEPKc
.text._ZN3bsl11fmt_options22fmt_options_impl_alignEPKcRNS_13safe_integralImEERKS4_
.text._ZN3bsl11fmt_options21fmt_options_impl_signEPKcRNS_13safe_integralImEE
.text._ZN3bsl11fmt_options31fmt_options_impl_alternate_formEPKcRNS_13safe_integralImEE
.text._ZN3bsl11fmt_options27fmt_options_impl_sign_awareEPKcRNS_13safe_integralImEE
.text._ZN3bsl11fmt_options22fmt_options_impl_widthEPKcRNS_13safe_integralImEERKS4_
.text._ZN3bsl11fmt_options21fmt_options_impl_typeEPKcRNS_13safe_integralImEE
.text._ZNR3bsl13safe_integralImEmLERKS1_
.text._ZN3bsl7to_umaxIcEENS_13safe_integralImEET_
.text._ZN3bsl20builtin_mul_overflowImEEbT_S1_PS1_
.text._ZN3bsl3outINS_7details14out_type_errorEE5writeEc
.text._ZN3bsl7details11putc_stderrEc
.text._ZN3bsl8fmt_implIRKNS_3outINS_7details14out_type_errorEEEmEEvOT_RKNS_11fmt_optionsERKNS_13safe_integralIT0_EE
.text._ZN3bsl7details18fmt_impl_align_preINS_3outINS0_14out_type_errorEEEEENS_13safe_integralImEERKT_RKNS_11fmt_optionsERKS6_b
.text._ZN3bsl3outINS_7details14out_type_errorEE5writeEPKc
.text._ZN3bsl7details18fmt_impl_align_sufINS_3outINS0_14out_type_errorEEEEEvRKT_RKNS_11fmt_optionsERKNS_13safe_integralImEEb
.text._ZN3bsl7details17fmt_impl_integralIRKNS_3outINS0_14out_type_errorEEEmEEvOT_RKNS_11fmt_optionsERKNS_13safe_integralIT0_EE
.text._ZN3bsl7forwardIRKNS_3outINS_7details14out_type_errorEEEEEOT_RNS_16remove_referenceIS7_E4typeE
.text._ZN3bsl7details11puts_stderrEPKc
.text._ZN3bsllsINS_7details14out_type_printEEENS_3outIT_EES5_c
.text._ZN3bsllsINS_7details14out_type_printEEENS_3outIT_EES5_PKc
.text._ZN3bsllsINS_7details14out_type_printEjLb1EEENS_3outIT_EES5_T0_
.text._ZNK3bsl15source_location9file_nameEv 
.text._ZNK3bsl15source_location4lineEv
.text._ZNK3bsl15source_location13function_nameEv
.text._ZN3bsl3outINS_7details14out_type_printEE5writeEc
.text._ZN3bsl3outINS_7details14out_type_printEE5writeEPKc
.text._ZN3bsl7details17get_integral_infoIjEENS0_22fmt_impl_integral_infoIT_EERKNS_11fmt_optionsENS_13safe_integralIS3_EE
.text._ZN3bsl7convertIjjEENS_13safe_integralIT_EERKT0_
.text._ZNK3bsl13safe_integralIjE7is_zeroEv
.text._ZN3bslrmIjEENS_13safe_integralIT_EERKS3_S5_
.text._ZNR3bsl13safe_integralIjEdVERKS1_
.text._ZN3bslgtIjEEbRKNS_13safe_integralIT_EES5_
.text._ZNR3bsl13safe_integralIjEmIERKS1_
.text._ZN3bsl7convertIjcEENS_13safe_integralIT_EERKT0_
.text._ZNR3bsl13safe_integralIjEpLERKS1_ .text._ZN3bsl13safe_integralIjE4zeroEb
.text._ZN3bsl13safe_integralIjEC2IjLb1EEET_b
.text._ZNR3bsl13safe_integralIjErMERKS1_
.text._ZN3bsl20builtin_mod_overflowIjEEbT_S1_PS1_
.text._ZN3bsl20builtin_div_overflowIjEEbT_S1_PS1_
.text._ZN3bsl20builtin_sub_overflowIjEEbT_S1_PS1_
.text._ZN3bsl20builtin_add_overflowIjEEbT_S1_PS1_
.text._ZN3bsl15source_locationC2EPKcS2_j
.text._ZNK3bsl13safe_integralItE7failureEv
.text._ZN3bsl13safe_integralItE4dataEv
.text._ZN7syscall17bf_vps_op_write32ERKNS_11bf_handle_tERKN3bsl13safe_integralItEERKNS4_ImEERKNS4_IjEE
.text._ZNK3bsl15basic_errc_typeIiE7successEv
.text._ZN3bslneIjEEbRKNS_13safe_integralIT_EES5_
.text._ZN3bslanIjEENS_13safe_integralIT_EERKS3_S5_
.text._ZNR3bsl13safe_integralIjEaNERKS1_
.text._ZN3bsllsINS_7details14out_type_errorEjLb1EEENS_3outIT_EES5_T0_
.text._ZN3bsl7details15print_thread_idINS0_14out_type_errorEEEvNS_3outIT_EE
.text._ZN3bsl14builtin_memsetEPvcRKNS_13safe_integralImEE
.text._ZN3bsl14builtin_memcpyEPvPKvRKNS_13safe_integralImEE
   01     .rodata .rodata._ZN3bsl11fmt_optionsC2EPKc
.rodata._ZN3bsl11fmt_options21fmt_options_impl_typeEPKcRNS_13safe_integralImEE
.rodata.str1.1 .rodata.cst16 .rodata.cst8
   02     .data .bss._ZN7example8g_handleE
   03
   None   .debug_loc .debug_abbrev .debug_info .debug_ranges .debug_str
.comment .debug_frame .debug_line .symtab .shstrtab .strtab
```

I am not sure if this is a bug or not, but it seems like something strange is
going on here. This is the toolchain file that we use to cross compile on
Windows for reference:
```
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_CXX_COMPILER_WORKS 1)

string(CONCAT HYPERVISOR_EXT_CXX_FLAGS
    "--target=x86_64-elf "
    "-ffreestanding "
    "-mno-mmx "
    "-mno-sse "
    "-mno-sse2 "
    "-mno-sse3 "
    "-mno-ssse3 "
    "-mno-sse4.1 "
    "-mno-sse4.2 "
    "-mno-sse4 "
    "-mno-avx "
    "-mno-aes "
    "-mno-sse4a "
    "-mcmodel=large "
    "-std=c++20 "
)

string(CONCAT HYPERVISOR_EXT_LINK_FLAGS
    "-static "
    "-nostdlib "
    "-z noexecstack "
    "-T ${CMAKE_BINARY_DIR}/toolchain/x64/ext.ld "
)

set(CMAKE_ASM_COMPILE_OBJECT
    "<CMAKE_CXX_COMPILER> ${HYPERVISOR_EXT_CXX_FLAGS} <DEFINES> <INCLUDES>
<FLAGS> -o <OBJECT> -c <SOURCE>")

set(CMAKE_CXX_COMPILE_OBJECT
    "<CMAKE_CXX_COMPILER> ${HYPERVISOR_EXT_CXX_FLAGS} <DEFINES> <INCLUDES>
<FLAGS> -o <OBJECT> -c <SOURCE>")

set(CMAKE_CXX_LINK_EXECUTABLE
    "${HYPERVISOR_CXX_LINKER} ${HYPERVISOR_EXT_LINK_FLAGS}
<CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>"
)
```

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210208/c3b4e657/attachment-0001.html>


More information about the llvm-bugs mailing list