immediate segmentation fault with LLVM/Clang 9

Denys Vlasenko vda.linux at googlemail.com
Fri Oct 25 10:10:34 UTC 2019


On Fri, Oct 25, 2019 at 10:57 AM Denys Vlasenko
<vda.linux at googlemail.com> wrote:
> On Fri, Oct 25, 2019 at 10:00 AM Romain Naour <romain.naour at smile.fr> wrote:
> > Le 25/10/2019 à 09:54, David Demelier a écrit :
> > > I don't know where is the appropriate place to ask. I've upgraded my toolchain
> > > to LLVM 9 on my Clang based Linux distribution and everything built and ran fine
> > > except... busybox.
> >
> > There is an initial patch for this issue:
> > http://lists.busybox.net/pipermail/busybox/2019-June/087306.html
>
> There should be a way to convince LLVM to not optimize out the store
> to a "constant".
>
> Then everything will work just fine, AND optimization
> (avoiding redundant loads of a known-unchanging pointer value)
> will still be making the code faster and smaller.

Specifically, just dropping "*const" is nearly 9kbytes larger than being
marginally smarter about it - say, by pulling address through an
opaque asm() so that llvm can no longer claim it knows it's a constant:

+static ALWAYS_INLINE void* not_const_pp(const void *p)
+{
+       void *pp;
+       __asm__ __volatile__(
+               "# forget that p points to const"
+               : /*outputs*/ "=r" (pp)
+               : /*inputs*/ "0" (p)
+       );
+       return pp;
+}

function                                             old     new   delta
builtin_fg_bg                                        232     347    +115
add_partition                                       1281    1395    +114
collect_info                                          44     127     +83
process_wait_result                                  467     549     +82
parse_expr                                          1038    1108     +70
collect_cpu                                          495     551     +56
conspy_main                                         1506    1561     +55
read_key                                             688     739     +51
zxc_vm_file                                           46      94     +48
rotate                                               725     770     +45
udhcpd_main                                         1559    1601     +42
kill_main                                           1193    1232     +39
xc_vm_run                                            131     168     +37
udhcp_recv_raw_packet                                642     673     +31
dpkg_main                                           4513    4542     +29
run_command                                          209     237     +28
tls_xread_record                                     715     742     +27
ifenslave_main                                       938     965     +27
write_irqcpu_stats                                   754     778     +24
input_delete                                          96     120     +24
ash_main                                            1488    1512     +24
put_16bit                                            117     140     +23
shell_builtin_read                                  1634    1656     +22
builtin_wait                                         456     477     +21
bb_getgroups                                         155     175     +20
sync_cursor                                          507     526     +19
set_vars_and_save_old                                198     217     +19
safe_write                                            55      74     +19
safe_read                                             55      74     +19
goto_lineno                                          136     154     +18
builtin_jobs                                         113     131     +18
xrealloc_getcwd_or_warn                              108     124     +16
dup_CLOEXEC                                           57      73     +16
.rodata                                           185981  185997     +16
file_insert                                          394     408     +14
parse_one_line                                      1181    1194     +13
input_backward                                       150     163     +13
safe_poll                                             85      97     +12
exec_builtin                                        2969    2981     +12
xc_read_line                                         390     401     +11
setup_redirects                                      418     429     +11
next_token                                          1031    1042     +11
bootchartd_main                                     2052    2063     +11
xdup_CLOEXEC_and_close                               106     116     +10
wait_any_nohang                                       41      51     +10
safe_waitpid                                          47      57     +10
readit                                                72      82     +10
fill_window_if_needed                                282     292     +10
update_local_clock                                   919     928      +9
klogd_main                                           551     560      +9
cmdio_write_ok                                        80      89      +9
cmdio_write_error                                     80      89      +9
bb_strtou                                            105     114      +9
bb_strtoi                                            128     137      +9
wait_for_exitstatus                                   66      74      +8
wait4pid                                             106     114      +8
test_main                                            446     454      +8
taskset_main                                         601     609      +8
showkey_main                                         622     630      +8
screen_dump                                          212     220      +8
rtc_xopen                                            165     173      +8
redirect                                            1008    1016      +8
goto_new_line                                         38      46      +8
unset_local_var                                      225     232      +7
restore_G_args                                       115     122      +7
parse_stream                                        2943    2950      +7
nonblock_immune_read                                 109     116      +7
add_match                                             94     101      +7
touch_main                                           386     392      +6
send_bits                                             80      86      +6
query_screen_dimensions                               64      70      +6
process_irq_counts                                   590     596      +6
builtin_exec                                         102     108      +6
readcmd                                              282     287      +5
get_free_block                                       182     187      +5
draw_custom                                          125     130      +5
builtin_shift                                        253     258      +5
builtin_read                                         206     211      +5
builtin_eval                                         314     319      +5
bi_windup                                             99     104      +5
bc_verror_msg                                        117     122      +5
procps_scan                                         1347    1351      +4
mult_lvl_cmp                                          70      74      +4
fgetsetversion                                       139     143      +4
checkjobs_and_fg_shell                                48      52      +4
write_stats                                          126     129      +3
wait_one                                             376     379      +3
singlemount                                         1395    1398      +3
re_wrap                                              458     461      +3
makemime_main                                        379     382      +3
goto_match                                           158     161      +3
get_uidgid                                           256     259      +3
diffreg                                             1800    1803      +3
convert_to_struct                                    322     325      +3
xstrtoull_range_sfx                                  285     287      +2
text_yank                                             77      79      +2
put_cur_glyph_and_inc_cursor                         160     162      +2
printLines                                           264     266      +2
ping                                                1614    1616      +2
checkjobs                                            235     237      +2
busybox_main                                         822     824      +2
bound_dot                                             61      63      +2
bc_num_printHex                                       82      84      +2
zxc_program_popResultAndCopyToVar                    994     995      +1
udhcpc_main                                         3028    3029      +1
udhcpc6_main                                        2983    2984      +1
switch_off_special_sigs                              156     157      +1
runsv_main                                          1786    1787      +1
rmdir_main                                           193     194      +1
regex_process                                        393     394      +1
main                                                 114     115      +1
ipcrm_main                                           749     750      +1
hdparm_main                                         5537    5538      +1
do_rescan                                            676     677      +1
dc_main                                              216     217      +1
collect_blk                                          806     807      +1
bc_main                                               86      87      +1
up_iface                                             169     168      -1
sleep_for_duration                                   133     132      -1
reformime_main                                       138     137      -1
read_cstate_counts                                   384     383      -1
pwdx_main                                            243     242      -1
pqdownheap                                           193     192      -1
passwd_main                                         1027    1026      -1
launch_helper                                        189     188      -1
check_consistency                                    462     461      -1
builtin_kill                                         350     349      -1
awk_getline                                          971     970      -1
zxc_program_num                                     1619    1617      -2
x_list_table                                         298     296      -2
write_stats_core                                    1767    1765      -2
step_time                                            392     390      -2
select_and_cluster                                  1211    1209      -2
search_name_hashtable                                136     134      -2
open_socket                                           86      84      -2
detect_link_iff                                      108     106      -2
write_superblock                                     108     105      -3
text_hole_delete                                     197     194      -3
status_line_bold                                     211     208      -3
status_line                                          170     167      -3
sig_child_handler                                    109     106      -3
push_filename                                         98      95      -3
processorstop                                        643     640      -3
parse_duration_str                                   256     253      -3
hush_exit                                            101      98      -3
get_line                                             163     160      -3
find_action                                          242     239      -3
expand_on_ifs                                        496     493      -3
devmem_main                                          457     454      -3
verify                                               981     977      -4
unix_do_one                                          609     605      -4
pseudo_exec_argv                                     490     486      -4
new_screen                                           110     106      -4
multiconvert                                         102      98      -4
fdisk_fatal                                           51      47      -4
expand_assignments                                   152     148      -4
add_logical                                          137     133      -4
zbc_parse_stmt_allow_NLINE_before                     93      88      -5
xmalloc_realpath_coreutils                           275     270      -5
xc_program_reset                                     110     105      -5
resume_main                                          479     474      -5
renice_main                                          388     383      -5
read_int                                             515     510      -5
log_locally                                          570     565      -5
get_sanitized_hdr                                    164     159      -5
getNum                                               363     358      -5
ftpcmd                                               191     186      -5
file_read                                             79      74      -5
echo_main                                            395     390      -5
buffer_pread                                         633     628      -5
timeout_handler                                      102      96      -6
stop_handler                                         102      96      -6
smtp_checkp                                          216     210      -6
set_pwd_var                                           99      93      -6
send_tree                                            394     388      -6
send_mail_command                                    113     107      -6
script_main                                         1098    1092      -6
reap_child                                           173     167      -6
pstree_main                                          376     370      -6
open_list_and_close                                  398     392      -6
modprobe_main                                        563     557      -6
getch_nowait                                         336     330      -6
get_boot                                            1861    1855      -6
fill_match_lines                                     157     151      -6
fb_drawfullrectangle                                 185     179      -6
deleteLines                                          233     227      -6
bc_num_printDigits                                   188     182      -6
zxc_lex_number                                       283     276      -7
xstrtou_range_sfx                                    310     303      -7
xc_program_binOpRetire                               149     142      -7
xc_parse_create                                      254     247      -7
undo_queue_commit                                     74      67      -7
status_print                                         127     120      -7
sigexit                                               77      70      -7
sig_term_handler                                      44      37      -7
sig_hangup_handler                                    44      37      -7
sig_alarm_handler                                     44      37      -7
set_status                                           188     181      -7
remap                                                147     140      -7
read_cpu_jiffy                                       190     183      -7
peek_inbuf                                            83      76      -7
ntp_init                                            1245    1238      -7
mount_it_now                                         273     266      -7
ll_proto_a2n                                         146     139      -7
less_gets                                            210     203      -7
getn                                                 103      96      -7
get_previous_history                                  61      54      -7
get_next_history                                      63      56      -7
fill_package_struct                                  475     468      -7
dump_by_user                                         114     107      -7
builtin_set                                          397     390      -7
builtin_pwd                                           62      55      -7
bc_parse_operator                                    294     287      -7
bc_num_printNewline                                   67      60      -7
alarm_intr                                            94      87      -7
add_proc                                             340     333      -7
wait_for_child_or_signal                             258     250      -8
screen_read_close                                    274     266      -8
lineedit_read_key                                    197     189      -8
ifplugd_main                                        1407    1399      -8
handle_input                                         748     740      -8
getvar_s                                             118     110      -8
display_process_list                                2217    2209      -8
write_table                                          165     156      -9
set_loop                                             797     788      -9
retry_network_setup                                   69      60      -9
process_timer_stats                                  519     510      -9
parse_and_put_prompt                                1003     994      -9
diff_main                                           1639    1630      -9
collect_time                                         215     206      -9
bc_program_addFunc                                   192     183      -9
scan_tree                                            271     261     -10
save_fd_on_redirect                                  300     290     -10
save_command_ps_at_cur_history                       117     107     -10
reread_config_file                                  1179    1169     -10
insert_job_into_table                                406     396     -10
generate_stream_from_string                          236     226     -10
append                                               106      96     -10
add_peers                                            265     255     -10
text_hole_make                                       209     198     -11
recv_and_process_client_pkt                          733     722     -11
leave_var_nest_level                                 156     145     -11
handle_upload_common                                 362     351     -11
get_local_var_value                                  373     362     -11
awk_exit                                             145     134     -11
print_found                                          422     410     -12
logdirs_reopen                                       123     111     -12
less_exit                                             98      86     -12
insertLine                                           210     198     -12
edir                                                 420     408     -12
catcher                                              380     368     -12
ask_and_unlink                                       166     154     -12
add_zone_ind2                                        119     107     -12
add_zone_ind                                         119     107     -12
add_zone_dind2                                       119     107     -12
update_num_lines                                     270     257     -13
seq_main                                             551     538     -13
iostat_main                                         2681    2668     -13
flush_block                                          636     623     -13
fgetsetflags                                         215     202     -13
ctrl_left                                            139     126     -13
connect_w_timeout                                    134     121     -13
clear_lines                                           99      86     -13
zxc_program_binOpPrep                                287     273     -14
zdc_program_assignStr                                282     268     -14
zdc_parse_mem                                        137     123     -14
process_module                                       918     904     -14
port_pasv_cleanup                                     59      45     -14
get_one_char                                         130     116     -14
builtin_break                                         93      79     -14
buffer_print                                         198     184     -14
bb_lookup_port                                       119     105     -14
add_lease                                            389     375     -14
xc_parse_pushNUM                                     122     107     -15
x_mode_flush                                          90      75     -15
unpack_package                                       819     804     -15
processorstart                                       445     430     -15
parse_conf                                          1790    1775     -15
collect_int                                          232     217     -15
tstp_handler                                         160     144     -16
search_package_hashtable                             172     156     -16
refresh                                              853     837     -16
print_inet_line                                      302     286     -16
hex2bin                                              252     236     -16
examine_file                                         214     198     -16
collect_thread_nr                                    203     187     -16
collect_fork                                         224     208     -16
collect_fd                                           208     192     -16
collect_ctx                                          224     208     -16
show_status_line                                     490     473     -17
reset_traps_to_defaults                              314     297     -17
zbc_parse_pushSTR                                    117      99     -18
start_stop_daemon_main                              1236    1218     -18
rmoldest                                             411     393     -18
fgetc_interactive                                    402     384     -18
exec_function                                         98      80     -18
handle_special                                       631     612     -19
fb_drawprogressbar                                   657     638     -19
compress_block                                       369     350     -19
zbc_parse_params                                     176     156     -20
rx_main                                              992     972     -20
list_table                                           805     785     -20
init_block                                           133     113     -20
cmdio_get_cmd_and_arg                                393     373     -20
xc_parse_free                                        136     115     -21
write_leases                                         241     220     -21
warn_geometry                                        132     111     -21
run_script                                           335     314     -21
deinit_S                                              75      54     -21
buffer_pwrite                                        812     791     -21
expand_one_var                                      3217    3195     -22
common_traceroute_main                              3982    3960     -22
cgi_io_loop_and_exit                                 672     650     -22
free_tab_completion_data                              85      62     -23
fgets_trim_sanitize                                  218     195     -23
collect_swp                                          247     224     -23
char_insert                                          559     535     -24
chain_loop                                           187     163     -24
builtin_source                                       480     456     -24
put_till_end_and_adv_cursor                           25       -     -25
parse_and_run_stream                                 201     176     -25
fsrealloc                                            191     166     -25
timestamp_and_log                                    828     802     -26
detect_link                                          252     226     -26
vi_main                                              359     332     -27
set_local_var                                        608     581     -27
httpd_main                                           701     674     -27
gzip_main                                            223     196     -27
ctrl_right                                           154     127     -27
send_cgi_and_exit                                    931     903     -28
reinitialize                                         216     188     -28
next_input_file                                      379     351     -28
buffer_fill_and_print                                204     176     -28
save_line                                            192     163     -29
recv_and_process_peer_pkt                           1244    1215     -29
install_sighandlers                                  314     285     -29
get_input_line                                       293     264     -29
ifupdown_main                                       1414    1384     -30
add_zone_common                                      280     250     -30
nvfree                                               259     228     -31
expand_vars_to_list                                 1196    1165     -31
chain_group                                          806     775     -31
undo_push                                            464     432     -32
syslogd_main                                        1235    1203     -32
split_f0                                             219     187     -32
sendmail_main                                       1661    1629     -32
finish_oldfile                                       170     137     -33
deflate                                             1140    1107     -33
get_jiffy_counts                                     443     409     -34
readwrite                                            805     770     -35
load_dep_bb                                          351     316     -35
get_irqs_from_interrupts                             696     661     -35
find_range                                           717     682     -35
bind_for_passive_mode                                169     134     -35
check_and_run_traps                                  330     294     -36
progress_meter                                       182     145     -37
delete_partition                                     456     419     -37
check_zones                                          314     277     -37
arping_main                                         1955    1918     -37
patch_main                                          2790    2752     -38
ct_tally                                             372     334     -38
chain_node                                           188     150     -38
collect_if                                           445     406     -39
recursive_check2                                    1156    1116     -40
logdir_open                                         1603    1562     -41
zbc_parse_name                                       447     405     -42
read_line                                            136      94     -42
m_status_print                                       375     333     -42
ntpd_main                                           1867    1824     -43
fbsplash_main                                       1770    1727     -43
check_zones2                                         333     289     -44
builtin_trap                                         581     537     -44
run_list                                            1502    1457     -45
flush_outbuf                                          46       -     -46
x_mode_print_optionally_squoted                      221     174     -47
pack_gzip                                            994     947     -47
nmeter_main                                          922     875     -47
dump_cmd_in_x_mode                                   227     180     -47
nc_main                                             1277    1229     -48
fail_hunk                                            226     178     -48
less_getch                                            49       -     -49
readLines                                            621     571     -50
hexedit_main                                        1264    1213     -51
zdc_parse_expr                                       615     563     -52
popmaildir_main                                      979     925     -54
input_tab                                           1411    1356     -55
find_alias                                           788     732     -56
display_topmem_process_list                          879     823     -56
bc_parse_pushJUMP_ZERO                                56       -     -56
bc_parse_pushJUMP                                     56       -     -56
parse_module                                         621     562     -59
powertop_main                                       1684    1624     -60
xc_program_print                                     936     875     -61
init_text_buffer                                     255     193     -62
dump_tree                                           1102    1040     -62
collect_mem                                          703     640     -63
do_syslogd                                          1213    1149     -64
netstat_main                                         636     571     -65
build_tree                                          1027     962     -65
recursive_check                                     1131    1064     -67
evaluate                                            4487    4419     -68
nvalloc                                              279     209     -70
zxc_vm_execute_FILE                                   72       -     -72
send_file_and_exit                                   845     773     -72
remove_job_from_table                                 72       -     -72
get_inode_common                                     350     275     -75
fdisk_main                                          3243    3168     -75
retrieve_file_data                                   749     673     -76
enslave                                              956     880     -76
put                                                   79       -     -79
send_headers                                         942     859     -83
acpid_main                                          1552    1464     -88
read_lines                                           981     890     -91
edit_file                                            927     836     -91
parse_program                                        506     414     -92
handle_incoming_and_exit                            2457    2365     -92
colon                                               3769    3670     -99
run_pipe                                            2153    2051    -102
less_main                                           3189    3085    -104
set_partition                                        109       -    -109
dolisten                                            1163    1054    -109
zxc_lex_next                                        2002    1889    -113
ed_main                                             2650    2527    -123
zbc_parse_expr                                      2714    2585    -129
xc_vm_init                                          1473    1337    -136
top_main                                            1488    1338    -150
ftpd_main                                           2948    2796    -152
svlogd_main                                         1773    1619    -154
mkfs_minix_main                                     3423    3257    -166
awk_main                                            1643    1469    -174
hush_main                                           1652    1455    -197
getty_main                                          1966    1768    -198
wget_main                                           3580    3368    -212
mpstat_main                                         1863    1600    -263
fsck_minix_main                                     3656    3380    -276
read_line_input                                     2930    2648    -282
do_cmd                                              7422    7072    -350
zxc_vm_process                                      1298   11791  +10493
zbc_parse_stmt_possibly_auto                        1920    2063    +143
zxc_program_exec                                   10733       -  -10733
------------------------------------------------------------------------------
(add/remove: 0/10 grow/shrink: 119/311 up/down: 12397/-20875)Total: -8478 bytes
   text       data        bss        dec        hex    filename
1071491       4202       1840    1077533     10711d    busybox_old
1062986       4202       1840    1069028     104fe4    busybox_unstripped


More information about the busybox mailing list