Skip to content

Conversation

@hiraditya
Copy link
Collaborator

Fixes: #68356

@hiraditya hiraditya changed the title Add cmake c,cxx,asm,linker flags [bolt] Add cmake c,cxx,asm,linker flags Oct 5, 2023
Copy link
Collaborator

@pirama-arumuga-nainar pirama-arumuga-nainar left a comment

Choose a reason for hiding this comment

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

Thanks for the fix @appujee!

Copy link
Contributor

@rafaelauler rafaelauler left a comment

Choose a reason for hiding this comment

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

Test is failing

@hiraditya
Copy link
Collaborator Author

Test is failing

BOLT :: runtime/X86/section-order.test fails even without the patch on my machine.

@hiraditya
Copy link
Collaborator Author

Test is failing

BOLT :: runtime/X86/section-order.test fails even without the patch on my machine.

nvm i see it passing on the baseline patch. something is up with this patch then.

@hiraditya
Copy link
Collaborator Author

After this patch readelf output is different.

$ cat base.readelf

There are 45 section headers, starting at offset 0x60b240:

Section Headers:
  [Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            0000000000000000 000000 000000 00      0   0  0
  [ 1] .interp           PROGBITS        0000000000000318 000318 00001c 00   A  0   0  1
  [ 2] .note.gnu.property NOTE           0000000000000338 000338 000020 00   A  0   0  8
  [ 3] .note.gnu.build-id NOTE           0000000000000358 000358 000024 00   A  0   0  4
  [ 4] .note.ABI-tag     NOTE            000000000000037c 00037c 000020 00   A  0   0  4
  [ 5] .hash             HASH            00000000000003a0 0003a0 00002c 04   A  7   0  8
  [ 6] .gnu.hash         GNU_HASH        00000000000003d0 0003d0 000024 00   A  7   0  8
  [ 7] .dynsym           DYNSYM          00000000000003f8 0003f8 000090 18   A  8   1  8
  [ 8] .dynstr           STRTAB          0000000000000488 000488 000088 00   A  0   0  1
  [ 9] .gnu.version      VERSYM          0000000000000510 000510 00000c 02   A  7   0  2
  [10] .gnu.version_r    VERNEED         0000000000000520 000520 000030 00   A  8   1  8
  [11] .rela.dyn         RELA            0000000000000550 000550 0000c0 18   A  7   0  8
  [12] .init             PROGBITS        0000000000001000 001000 000017 00  AX  0   0  4
  [13] .plt              PROGBITS        0000000000001020 001020 000010 10  AX  0   0 16
  [14] .plt.got          PROGBITS        0000000000001030 001030 000008 08  AX  0   0  8
  [15] .bolt.org.text    PROGBITS        0000000000001040 001040 0000f7 00  AX  0   0 16
  [16] .fini             PROGBITS        0000000000001138 001138 000009 00  AX  0   0  4
  [17] .rodata           PROGBITS        0000000000002000 002000 000004 04  AM  0   0  4
  [18] .bolt.org.eh_frame_hdr PROGBITS   0000000000002004 002004 000024 00   A  0   0  4
  [19] .bolt.org.eh_frame PROGBITS       0000000000002028 002028 000088 00   A  0   0  8
  [20] .init_array       INIT_ARRAY      0000000000003df0 002df0 000008 08  WA  0   0  8
  [21] .fini_array       FINI_ARRAY      0000000000003df8 002df8 000008 08  WA  0   0  8
  [22] .dynamic          DYNAMIC         0000000000003e00 002e00 0001c0 10  WA  8   0  8
  [23] .got              PROGBITS        0000000000003fc0 002fc0 000028 08  WA  0   0  8
  [24] .got.plt          PROGBITS        0000000000003fe8 002fe8 000018 08  WA  0   0  8
  [25] .data             PROGBITS        0000000000004000 003000 000010 00  WA  0   0  8
  [26] .tm_clone_table   PROGBITS        0000000000004010 003010 000000 00  WA  0   0  8
  [27] .bss              NOBITS          0000000000004010 003010 000008 00  WA  0   0  1
  [28] .text             PROGBITS        0000000000400000 400000 000274 00  AX  0   0 2097152
  [29] .text.injected    PROGBITS        0000000000400280 400280 00006f 00  AX  0   0 64
  [30] .eh_frame         PROGBITS        0000000000600000 600000 0000b8 00   A  0   0  8
  [31] .bolt.instr.counters PROGBITS     0000000000601000 601000 00103e 00  WA  0   0 4096
  [32] .text.bolt.extra.1 PROGBITS       0000000000602040 602040 0060ba 00  AX  0   0 16
  [33] .rodata.str1.1.bolt.extra.1 PROGBITS 00000000006080fa 6080fa 00006e 00   A  0   0  1
  [34] .rodata.str1.16.bolt.extra.1 PROGBITS 0000000000608170 608170 000066 00   A  0   0 16
  [35] .rodata.bolt.extra.1 PROGBITS     00000000006081d8 6081d8 000008 00   A  0   0  8
  [36] .data.bolt.extra.1 PROGBITS       0000000000609000 609000 000010 00  WA  0   0  8
  [37] .bss.bolt.extra.1 PROGBITS        0000000000609010 609010 001020 00  WA  0   0 16
  [38] .eh_frame_hdr     PROGBITS        000000000060a030 60a030 00002c 00   A  0   0  1
  [39] .comment          PROGBITS        0000000000000000 60a05c 00001e 01  MS  0   0  1
  [40] .symtab           SYMTAB          0000000000000000 60a080 000738 18     41  56  8
  [41] .strtab           STRTAB          0000000000000000 60a7b8 00033a 00      0   0  1
  [42] .shstrtab         STRTAB          0000000000000000 60aaf2 000236 00      0   0  1
  [43] .bolt.instr.tables NOTE           0000000000000000 60ad28 00037c 00      0   0  1
  [44] .note.bolt_info   NOTE            0000000000000000 60b0a4 000194 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
  L (link order), O (extra OS processing required), G (group), T (TLS),
  C (compressed), x (unknown), o (OS specific), E (exclude),
  R (retain), l (large), p (processor specific)

$ cat mod.readelf

There are 75 section headers, starting at offset 0x60bad0:

Section Headers:
  [Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            0000000000000000 000000 000000 00      0   0  0
  [ 1] .interp           PROGBITS        0000000000000318 000318 00001c 00   A  0   0  1
  [ 2] .note.gnu.property NOTE           0000000000000338 000338 000020 00   A  0   0  8
  [ 3] .note.gnu.build-id NOTE           0000000000000358 000358 000024 00   A  0   0  4
  [ 4] .note.ABI-tag     NOTE            000000000000037c 00037c 000020 00   A  0   0  4
  [ 5] .hash             HASH            00000000000003a0 0003a0 00002c 04   A  7   0  8
  [ 6] .gnu.hash         GNU_HASH        00000000000003d0 0003d0 000024 00   A  7   0  8
  [ 7] .dynsym           DYNSYM          00000000000003f8 0003f8 000090 18   A  8   1  8
  [ 8] .dynstr           STRTAB          0000000000000488 000488 000088 00   A  0   0  1
  [ 9] .gnu.version      VERSYM          0000000000000510 000510 00000c 02   A  7   0  2
  [10] .gnu.version_r    VERNEED         0000000000000520 000520 000030 00   A  8   1  8
  [11] .rela.dyn         RELA            0000000000000550 000550 0000c0 18   A  7   0  8
  [12] .init             PROGBITS        0000000000001000 001000 000017 00  AX  0   0  4
  [13] .plt              PROGBITS        0000000000001020 001020 000010 10  AX  0   0 16
  [14] .plt.got          PROGBITS        0000000000001030 001030 000008 08  AX  0   0  8
  [15] .bolt.org.text    PROGBITS        0000000000001040 001040 0000f7 00  AX  0   0 16
  [16] .fini             PROGBITS        0000000000001138 001138 000009 00  AX  0   0  4
  [17] .rodata           PROGBITS        0000000000002000 002000 000004 04  AM  0   0  4
  [18] .bolt.org.eh_frame_hdr PROGBITS   0000000000002004 002004 000024 00   A  0   0  4
  [19] .bolt.org.eh_frame PROGBITS       0000000000002028 002028 000088 00   A  0   0  8
  [20] .init_array       INIT_ARRAY      0000000000003df0 002df0 000008 08  WA  0   0  8
  [21] .fini_array       FINI_ARRAY      0000000000003df8 002df8 000008 08  WA  0   0  8
  [22] .dynamic          DYNAMIC         0000000000003e00 002e00 0001c0 10  WA  8   0  8
  [23] .got              PROGBITS        0000000000003fc0 002fc0 000028 08  WA  0   0  8
  [24] .got.plt          PROGBITS        0000000000003fe8 002fe8 000018 08  WA  0   0  8
  [25] .data             PROGBITS        0000000000004000 003000 000010 00  WA  0   0  8
  [26] .tm_clone_table   PROGBITS        0000000000004010 003010 000000 00  WA  0   0  8
  [27] .bss              NOBITS          0000000000004010 003010 000008 00  WA  0   0  1
  [28] .text             PROGBITS        0000000000400000 400000 000274 00  AX  0   0 2097152
  [29] .text.injected    PROGBITS        0000000000400280 400280 00006f 00  AX  0   0 64
  [30] .eh_frame         PROGBITS        0000000000600000 600000 0000b8 00   A  0   0  8
  [31] .bolt.instr.counters PROGBITS     0000000000601000 601000 00103e 00  WA  0   0 4096
  [32] .text.memcpy.bolt.extra.1 PROGBITS 0000000000602040 602040 0000a8 00  AX  0   0 16
  [33] .text.memmove.bolt.extra.1 PROGBITS 00000000006020f0 6020f0 000178 00  AX  0   0 16
  [34] .text.memset.bolt.extra.1 PROGBITS 0000000000602270 602270 00006e 00  AX  0   0 16
  [35] .text.memcmp.bolt.extra.1 PROGBITS 00000000006022e0 6022e0 000031 00  AX  0   0 16
  [36] .text.__bolt_instr_clear_counters.bolt.extra.1 PROGBITS 0000000000602320 602320 0000fb 00  AX  0   0 16
  [37] .text.__bolt_instr_data_dump.bolt.extra.1 PROGBITS 0000000000602420 602420 003471 00  AX  0   0 16
  [38] .text._ZN12_GLOBAL__N_16assertEbPKc.bolt.extra.1 PROGBITS 00000000006058a0 6058a0 0000f4 00  AX  0   0 16
  [39] .text._ZN12_GLOBAL__N_118visitCallFlowEntryERNS_17CallFlowEntryBaseEiPNS_20ProfileWriterContextE.bolt.extra.1 PROGBITS 00000000006059a0 6059a0 00020e 00  AX  0   0 16
  [40] .text._Z12watchProcessv.bolt.extra.1 PROGBITS 0000000000605bb0 605bb0 000209 00  AX  0   0 16
  [41] .text._ZN12_GLOBAL__N_111openProfileEv.bolt.extra.1 PROGBITS 0000000000605dc0 605dc0 000462 00  AX  0   0 16
  [42] .text.__bolt_instr_setup.bolt.extra.1 PROGBITS 0000000000606230 606230 00042b 00  AX  0   0 16
  [43] .text.__bolt_instr_indirect_call.bolt.extra.1 PROGBITS 0000000000606660 606660 00004c 00  AX  0   0 16
  [44] .text.__bolt_instr_indirect_tailcall.bolt.extra.1 PROGBITS 00000000006066b0 6066b0 00004c 00  AX  0   0 16
  [45] .text.instrumentIndirectCall.bolt.extra.1 PROGBITS 0000000000606700 606700 00010e 00  AX  0   0 16
  [46] .text.__bolt_instr_start.bolt.extra.1 PROGBITS 0000000000606810 606810 000040 00  AX  0   0 16
  [47] .text.__bolt_instr_fini.bolt.extra.1 PROGBITS 0000000000606850 606850 00002d 00  AX  0   0 16
  [48] .text._ZN12_GLOBAL__N_18__get_pcEv.bolt.extra.1 PROGBITS 0000000000606880 606880 000005 00  AX  0   0 16
  [49] .text._ZN12_GLOBAL__N_116BumpPtrAllocator8allocateEm.bolt.extra.1 PROGBITS 0000000000606890 606890 000228 00  AX  0   0 16
  [50] .text._ZN12_GLOBAL__N_15GraphD2Ev.bolt.extra.1 PROGBITS 0000000000606ac0 606ac0 0000c8 00  AX  0   0 16
  [51] .text._ZN12_GLOBAL__N_116BumpPtrAllocator10deallocateEPv.bolt.extra.1 PROGBITS 0000000000606b90 606b90 0001fc 00  AX  0   0 16
  [52] .text._ZN12_GLOBAL__N_112serializeLocERKNS_20ProfileWriterContextEPcNS_8LocationEj.bolt.extra.1 PROGBITS 0000000000606d90 606d90 00020e 00  AX  0   0 16
  [53] .text._ZN12_GLOBAL__N_115SimpleHashTableINS_17CallFlowEntryBaseELj11939ELj233EE15getOrAllocEntryEmRNS_16BumpPtrAllocatorE.bolt.extra.1 PROGBITS 0000000000606fa0 606fa0 0003f2 00  AX  0   0 16
  [54] .text._ZN12_GLOBAL__N_119visitIndCallCounterERNS_24SimpleHashTableEntryBaseEiiPNS_20ProfileWriterContextE.bolt.extra.1 PROGBITS 00000000006073a0 6073a0 0005f5 00  AX  0   0 16
  [55] .text._ZN12_GLOBAL__N_115SimpleHashTableINS_24SimpleHashTableEntryBaseELj7ELj7EE14forEachElementIJiiPNS_20ProfileWriterContextEEEEvPFvRS1_DpT_EjPS1_S8_.bolt.extra.1 PROGBITS 00000000006079a0 6079a0 00008c 00  AX  0   0 16
  [56] .text._ZN12_GLOBAL__N_115SimpleHashTableINS_24SimpleHashTableEntryBaseELj7ELj7EE14forEachElementIJEEEvPFvRS1_DpT_EjPS1_S6_.bolt.extra.1 PROGBITS 0000000000607a30 607a30 0001ba 00  AX  0   0 16
  [57] .text._ZN12_GLOBAL__N_115SimpleHashTableINS_17CallFlowEntryBaseELj11939ELj233EE14forEachElementIJiPNS_20ProfileWriterContextEEEEvPFvRS1_DpT_EjPS1_S8_.bolt.extra.1 PROGBITS 0000000000607bf0 607bf0 000099 00  AX  0   0 16
  [58] .text._ZN12_GLOBAL__N_115SimpleHashTableINS_24SimpleHashTableEntryBaseELj7ELj7EE15getOrAllocEntryEmRNS_16BumpPtrAllocatorE.bolt.extra.1 PROGBITS 0000000000607c90 607c90 00046a 00  AX  0   0 16
  [59] .rodata.str1.1.bolt.extra.1 PROGBITS 00000000006080fa 6080fa 00006e 00   A  0   0  1
  [60] .rodata.str1.16.bolt.extra.1 PROGBITS 0000000000608170 608170 000066 00   A  0   0 16
  [61] .rodata._ZN12_GLOBAL__N_114MaskAllSignalsE.bolt.extra.1 PROGBITS 00000000006081d8 6081d8 000008 00   A  0   0  8
  [62] .data._ZN12_GLOBAL__N_121GlobalIndCallCountersE.bolt.extra.1 PROGBITS 0000000000609000 609000 000008 00  WA  0   0  8
  [63] .data._ZN12_GLOBAL__N_123GlobalWriteProfileMutexE.bolt.extra.1 PROGBITS 0000000000609008 609008 000008 00  WA  0   0  8
  [64] .bss._ZN12_GLOBAL__N_115TextBaseAddressE.bolt.extra.1 PROGBITS 0000000000609010 609010 000008 00  WA  0   0  8
  [65] .bss._ZN12_GLOBAL__N_121GlobalMetadataStorageE.bolt.extra.1 PROGBITS 0000000000609018 609018 000008 00  WA  0   0  8
  [66] .bss._ZN12_GLOBAL__N_111GlobalAllocE.bolt.extra.1 PROGBITS 0000000000609020 609020 000008 00  WA  0   0  8
  [67] .bss._ZZN12_GLOBAL__N_113getBinaryPathEvE10TargetPath.bolt.extra.1 PROGBITS 0000000000609030 609030 001000 00  WA  0   0 16
  [68] .eh_frame_hdr     PROGBITS        000000000060a030 60a030 00002c 00   A  0   0  1
  [69] .comment          PROGBITS        0000000000000000 60a05c 00001e 01  MS  0   0  1
  [70] .symtab           SYMTAB          0000000000000000 60a080 000738 18     71  56  8
  [71] .strtab           STRTAB          0000000000000000 60a7b8 00033a 00      0   0  1
  [72] .shstrtab         STRTAB          0000000000000000 60aaf2 000ad6 00      0   0  1
  [73] .bolt.instr.tables NOTE           0000000000000000 60b5c8 00037c 00      0   0  1
  [74] .note.bolt_info   NOTE            0000000000000000 60b944 000184 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
  L (link order), O (extra OS processing required), G (group), T (TLS),
  C (compressed), x (unknown), o (OS specific), E (exclude),
  R (retain), l (large), p (processor specific)

@hiraditya hiraditya requested a review from maksfb October 26, 2023 23:42
@maksfb maksfb requested a review from aaupov October 27, 2023 00:03
@hiraditya
Copy link
Collaborator Author

@rafaelauler please review the patch as i've fixed the testcase.

@aaupov
Copy link
Contributor

aaupov commented Oct 30, 2023

The issue is that we don't want arbitrary flags being passed to BOLT runtime library build – they are configured to be freestanding. Specifically, runtime library shouldn't depend on host libgcc_s.

The proper solution would probably be along the lines of LLVM_ENABLE_RUNTIMES.

@hiraditya
Copy link
Collaborator Author

The issue is that we don't want arbitrary flags being passed to BOLT runtime library build – they are configured to be freestanding. Specifically, runtime library shouldn't depend on host libgcc_s.

Ah i see -ffreestanding in bolt/runtime/CMakeLists.txt. Do we also need -nostdlib and -nodefaultlibs flags? I wonder why i get -lgcc -lgcc_s in the link line.

The proper solution would probably be along the lines of LLVM_ENABLE_RUNTIMES.

Makes sense. Do you have wip patches for this?

@aaupov
Copy link
Contributor

aaupov commented Nov 3, 2023

The issue is that we don't want arbitrary flags being passed to BOLT runtime library build – they are configured to be freestanding. Specifically, runtime library shouldn't depend on host libgcc_s.

Ah i see -ffreestanding in bolt/runtime/CMakeLists.txt. Do we also need -nostdlib and -nodefaultlibs flags? I wonder why i get -lgcc -lgcc_s in the link line.

I think we need all of the flags per this answer: https://stackoverflow.com/questions/59612257/difference-between-ffreestanding-and-nostdlib-when-compiling-with-gcc

The options control two parts of the process:

-freestanding indicates to the compiler that it should be a freestanding one, AFAIK the only effect is disabling some built-in functions like memcpy;

-nostdlib indicates that no libraries and no start up files should be linked by default.

The proper solution would probably be along the lines of LLVM_ENABLE_RUNTIMES.

Makes sense. Do you have wip patches for this?

Unfortunately no, I'm not an expert in runtimes builds. @petrhosek – do you have any tips/starting points?

@petrhosek
Copy link
Member

Unfortunately no, I'm not an expert in runtimes builds. @petrhosek – do you have any tips/starting points?

Nothing other than including the BOLT runtime in LLVM_ENABLE_RUNTIMES, see what breaks and then keep on iterating until you get it compiling.

@hiraditya hiraditya closed this Dec 4, 2024
@hiraditya hiraditya deleted the bolt_rt branch December 4, 2024 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bolt] bolt_rt cmake configure fails when a custom sysroot is provided

5 participants