Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Empty C file leads to a tr binary #1362

Open
trvv opened this issue Feb 6, 2025 · 0 comments
Open

Bug: Empty C file leads to a tr binary #1362

trvv opened this issue Feb 6, 2025 · 0 comments
Labels
medium severity Used to report medium severity bugs (e.g. Malfunctioning Features but still useable)

Comments

@trvv
Copy link

trvv commented Feb 6, 2025

Contact Details

No response

What happened?

Compiling an empty C file with cosmocc results in a binary that does tr stuff. I would expect it to error, probably. At the very least not be a random utility binary if it's supposed to include the basic tracing stuff anyway. Seems harmless but bizarre and might be related to problems that are more severe, but I lack the knowledge of cosmo to get a grasp on why this might be happening.

Running on M2 laptop, macOS 14.7.3

GCC or CLANG, doesn't matter. Running an ftrace tells me that it immediately jumps into the _tr function.

Asciinema attached because it sounds ridiculous/impossible: https://asciinema.org/a/6DfXd4I990IDKgtB2utq6qxVf

I would debug a little closer but lldb does not work with cosmo binaries it seems (maybe I'm doing something wrong?

Version

cosmocc (GCC) 14.1.0

What operating system are you seeing the problem on?

Mac

Relevant log output

tv@bbb cosmo-tests % ./test --strace
SYS  91102  91102             36'368 issetugid() → 0
SYS  91102  91102             39'984 getenv("COMDBG") → NULL
SYS  91102  91102             41'344 issetugid() → 0
SYS  91102  91102             42'112 GetProgramExecutableName() → "/Users/tv/Developer/local/cosmo-tests/test"
SYS  91102  91102             47'328 openat(AT_FDCWD, "/Users/tv/Developer/local/cosmo-tests/test.dbg", O_RDONLY|O_CLOEXEC) → -1 ENOENT
SYS  91102  91102             55'440 openat(AT_FDCWD, "/Users/tv/Developer/local/cosmo-tests/test.com.dbg", O_RDONLY|O_CLOEXEC) → 3
SYS  91102  91102             58'016 lseek(3, 0, SEEK_END) → 1'590'462
SYS  91102  91102             62'384 mmap(0, 1'590'462, PROT_READ, MAP_SHARED, 3, 0) → 0x10051c000 (11'354'112 bytes total)
SYS  91102  91102             66'704 munmap(0x10051c000, 1'590'462) → 0 (9'748'480 bytes total)
SYS  91102  91102             68'592 close(3) → 0
SYS  91102  91102             75'408 openat(AT_FDCWD, "/Users/tv/Developer/local/cosmo-tests/test.aarch64.elf", O_RDONLY|O_CLOEXEC) → 3
SYS  91102  91102             77'312 lseek(3, 0, SEEK_END) → 1'176'622
SYS  91102  91102             90'416 mmap(0, 1'176'622, PROT_READ, MAP_SHARED, 3, 0) → 0x10051c000 (10'928'128 bytes total)
SYS  91102  91102            104'496 munmap(0x10051c000, 1'176'622) → 0 (9'748'480 bytes total)
SYS  91102  91102            107'280 close(3) → 0
SYS  91102  91102            108'400 getenv("TERM") → "xterm-256color"
SYS  91102  91102            110'512 mmap(0, 65'536, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) → 0x10051c000 (9'814'016 bytes total)
SYS  91102  91102            118'864 fstat(0, [{.st_size=0, .st_mode=020620, .st_uid=501, .st_gid=4, .st_dev=0x371e336d, .st_ino=0x2ef, .st_rdev=268'435'457, .st_blksize=65'536}]) → 0
SYS  91102  91102            120'768 getenv("COSMOPOLITAN_DISABLE_ZIPOS") → NULL
SYS  91102  91102            121'968 issetugid() → 0
SYS  91102  91102            122'976 getenv("COSMOPOLITAN_INIT_ZIPOS") → NULL
SYS  91102  91102            123'904 GetProgramExecutableName() → "/Users/tv/Developer/local/cosmo-tests/test"
SYS  91102  91102            135'264 openat(AT_FDCWD, "/Users/tv/Developer/local/cosmo-tests/test", O_RDONLY) → 3
SYS  91102  91102            137'904 fstat(3, [{.st_size=631'771, .st_blocks=634'880/512, .st_mode=0100755, .st_uid=501, .st_gid=20, .st_dev=0x100000d, .st_ino=0xda6bf1}]) → 0
SYS  91102  91102            141'344 mmap(0, 631'771, PROT_READ, MAP_SHARED, 3, 0) → 0x10052c000 (10'452'992 bytes total)
SYS  91102  91102            146'560 munmap(0x10052c000, 589'824) → 0 (9'863'168 bytes total)
SYS  91102  91102            148'560 mmap(0, 24, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) → 0x10052c000 (9'879'552 bytes total)
SYS  91102  91102            151'680 close(3) → 0
SYS  91102  91102            152'384 __zipos_get("/Users/tv/Developer/local/cosmo-tests/test") → 0
SYS  91102  91102            154'080 mmap(0, 49'152, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) → 0x100530000 (9'928'704 bytes total)
SYS  91102  91102            455'856 inflate([u"SYMT☺   T♥       └       └          ◘   "...], 49'152, u"φ£{xUW¥░W☻J-¡╨╓↓ót╛`[♂òû;♣K§Brræ$‘MNÜ`δl"..., 12'892) → 0
SYS  91102  91102            459'232 GetSymbolTableFromZip() → 0x100530000
usage: tr [-Ccs] string1 string2
       tr [-Cc] -d string1
       tr [-Cc] -s string1
       tr [-Cc] -ds string1 string2
SYS  91102  91102            464'368 writev(2, {{, 0}, {u"usage: tr [-Ccs] string1 string2◙       "..., 123}}, 2) → 123
SYS  91102  91102            466'064 exit(1)
SYS  91102  91102            466'912 __cxa_finalize(__gdtoa_Bclear, 0)
SYS  91102  91102            469'536 __cxa_finalize(fflush, 0)
SYS  91102  91102            470'608 _Exit(1)

FUN  91141  91141            989'648  1'352 main
FUN  91141  91141            995'344  1'368   _tr
FUN  91141  91141            996'288  1'448     __getopt
FUN  91141  91141            997'056  1'448     usage
FUN  91141  91141            997'776  1'464       fwrite
FUN  91141  91141            999'968  1'512         flockfile
FUN  91141  91141          1'000'768  1'528           _pthread_mutex_lock
FUN  91141  91141          1'001'920  1'544             pthread_mutex_lock_impl
FUN  91141  91141          1'003'488  1'608               nsync_mu_lock
FUN  91141  91141          1'004'880  1'640                 __aarch64_cas4_acq
FUN  91141  91141          1'005'712  1'512         fwrite_unlocked
FUN  91141  91141          1'006'480  1'656           writev
FUN  91141  91141          1'007'232  1'704             writev_impl
FUN  91141  91141          1'008'064  1'720               sys_writev
FUN  91141  91141          1'008'800  1'720               systemfive
FUN  91141  91141          1'009'536  1'720               systemfive_cancellable
usage: tr [-Ccs] string1 string2
       tr [-Cc] -d string1
       tr [-Cc] -s string1
       tr [-Cc] -ds string1 string2
FUN  91141  91141          1'011'600  1'512         funlockfile
FUN  91141  91141          1'012'400  1'528           _pthread_mutex_unlock
FUN  91141  91141          1'013'184  1'544             pthread_mutex_unlock_impl
FUN  91141  91141          1'014'048  1'592               nsync_mu_unlock
FUN  91141  91141          1'014'800  1'624                 __aarch64_cas4_rel
FUN  91141  91141          1'015'584  1'464       exit
FUN  91141  91141          1'016'368  1'512         __cxa_thread_finalize
FUN  91141  91141          1'017'200  1'512         __cxa_finalize
FUN  91141  91141          1'017'952  1'576           __cxa_lock
FUN  91141  91141          1'018'672  1'592             _pthread_mutex_lock
FUN  91141  91141          1'019'440  1'608               pthread_mutex_lock_impl
FUN  91141  91141          1'020'480  1'672                 __aarch64_cas4_acq
FUN  91141  91141          1'021'248  1'576           __cxa_unlock
FUN  91141  91141          1'022'032  1'592             _pthread_mutex_unlock
FUN  91141  91141          1'022'768  1'608               pthread_mutex_unlock_impl
FUN  91141  91141          1'023'584  1'656                 __aarch64_ldadd4_rel
FUN  91141  91141          1'025'776  1'576           __gdtoa_Bclear
FUN  91141  91141          1'027'216  1'656             __gdtoa_lock1
FUN  91141  91141          1'027'968  1'672               _pthread_mutex_lock
FUN  91141  91141          1'028'720  1'688                 pthread_mutex_lock_impl
FUN  91141  91141          1'029'616  1'752                   __aarch64_cas4_acq
FUN  91141  91141          1'030'384  1'656             __gdtoa_lock
FUN  91141  91141          1'031'120  1'672               _pthread_mutex_lock
FUN  91141  91141          1'031'840  1'688                 pthread_mutex_lock_impl
FUN  91141  91141          1'032'640  1'752                   __aarch64_cas4_acq
FUN  91141  91141          1'033'552  1'656             __gdtoa_unlock
FUN  91141  91141          1'034'288  1'672               _pthread_mutex_unlock
FUN  91141  91141          1'035'104  1'688                 pthread_mutex_unlock_impl
FUN  91141  91141          1'035'952  1'736                   __aarch64_ldadd4_rel
FUN  91141  91141          1'036'720  1'656             __gdtoa_unlock1
FUN  91141  91141          1'037'520  1'672               _pthread_mutex_unlock
FUN  91141  91141          1'038'336  1'688                 pthread_mutex_unlock_impl
FUN  91141  91141          1'039'104  1'736                   __aarch64_ldadd4_rel
FUN  91141  91141          1'039'824  1'576           __cxa_lock
FUN  91141  91141          1'040'528  1'592             _pthread_mutex_lock
FUN  91141  91141          1'041'360  1'608               pthread_mutex_lock_impl
FUN  91141  91141          1'042'256  1'672                 __aarch64_cas4_acq
FUN  91141  91141          1'042'992  1'576           __cxa_unlock
FUN  91141  91141          1'043'696  1'592             _pthread_mutex_unlock
FUN  91141  91141          1'044'416  1'608               pthread_mutex_unlock_impl
FUN  91141  91141          1'045'200  1'656                 __aarch64_ldadd4_rel
FUN  91141  91141          1'046'128  1'576           fflush
FUN  91141  91141          1'046'880  1'640             __stdio_lock
FUN  91141  91141          1'047'616  1'656               _pthread_mutex_lock
FUN  91141  91141          1'048'336  1'672                 pthread_mutex_lock_impl
FUN  91141  91141          1'049'104  1'736                   __aarch64_cas4_acq
FUN  91141  91141          1'049'936  1'640             __stdio_ref
FUN  91141  91141          1'050'736  1'656               __aarch64_ldadd4_relax
FUN  91141  91141          1'051'488  1'640             __stdio_unlock
FUN  91141  91141          1'052'192  1'656               _pthread_mutex_unlock
FUN  91141  91141          1'052'960  1'672                 pthread_mutex_unlock_impl
FUN  91141  91141          1'053'760  1'720                   __aarch64_ldadd4_rel
FUN  91141  91141          1'054'656  1'640             flockfile
FUN  91141  91141          1'055'408  1'656               _pthread_mutex_lock
FUN  91141  91141          1'056'160  1'672                 pthread_mutex_lock_impl
FUN  91141  91141          1'056'944  1'736                   nsync_mu_lock
FUN  91141  91141          1'057'680  1'768                     __aarch64_cas4_acq
FUN  91141  91141          1'058'480  1'640             fflush_unlocked
FUN  91141  91141          1'059'280  1'640             funlockfile
FUN  91141  91141          1'060'016  1'656               _pthread_mutex_unlock
FUN  91141  91141          1'060'768  1'672                 pthread_mutex_unlock_impl
FUN  91141  91141          1'061'568  1'720                   nsync_mu_unlock
FUN  91141  91141          1'062'400  1'752                     __aarch64_cas4_rel
FUN  91141  91141          1'063'216  1'640             __stdio_lock
FUN  91141  91141          1'063'920  1'656               _pthread_mutex_lock
FUN  91141  91141          1'064'640  1'672                 pthread_mutex_lock_impl
FUN  91141  91141          1'065'424  1'736                   __aarch64_cas4_acq
FUN  91141  91141          1'066'192  1'640             __stdio_unref_unlocked
FUN  91141  91141          1'067'072  1'656               __stdio_unref_impl
FUN  91141  91141          1'067'840  1'720                 __aarch64_cas4_acq_rel
FUN  91141  91141          1'068'640  1'640             __stdio_ref
FUN  91141  91141          1'069'344  1'656               __aarch64_ldadd4_relax
FUN  91141  91141          1'070'096  1'640             __stdio_unlock
FUN  91141  91141          1'071'024  1'656               _pthread_mutex_unlock
FUN  91141  91141          1'071'776  1'672                 pthread_mutex_unlock_impl
FUN  91141  91141          1'072'576  1'720                   __aarch64_ldadd4_rel
FUN  91141  91141          1'073'312  1'640             flockfile
FUN  91141  91141          1'074'016  1'656               _pthread_mutex_lock
FUN  91141  91141          1'074'928  1'672                 pthread_mutex_lock_impl
FUN  91141  91141          1'075'696  1'736                   nsync_mu_lock
FUN  91141  91141          1'076'432  1'768                     __aarch64_cas4_acq
FUN  91141  91141          1'077'168  1'640             fflush_unlocked
FUN  91141  91141          1'077'920  1'640             funlockfile
FUN  91141  91141          1'078'624  1'656               _pthread_mutex_unlock
FUN  91141  91141          1'079'472  1'672                 pthread_mutex_unlock_impl
FUN  91141  91141          1'080'336  1'720                   nsync_mu_unlock
FUN  91141  91141          1'081'088  1'752                     __aarch64_cas4_rel
FUN  91141  91141          1'081'824  1'640             __stdio_lock
FUN  91141  91141          1'082'544  1'656               _pthread_mutex_lock
FUN  91141  91141          1'083'328  1'672                 pthread_mutex_lock_impl
FUN  91141  91141          1'084'144  1'736                   __aarch64_cas4_acq
FUN  91141  91141          1'084'880  1'640             __stdio_unref_unlocked
FUN  91141  91141          1'085'648  1'656               __stdio_unref_impl
FUN  91141  91141          1'086'400  1'720                 __aarch64_cas4_acq_rel
FUN  91141  91141          1'087'152  1'640             __stdio_ref
FUN  91141  91141          1'088'032  1'656               __aarch64_ldadd4_relax
FUN  91141  91141          1'088'768  1'640             __stdio_unlock
FUN  91141  91141          1'089'472  1'656               _pthread_mutex_unlock
FUN  91141  91141          1'090'240  1'672                 pthread_mutex_unlock_impl
FUN  91141  91141          1'091'008  1'720                   __aarch64_ldadd4_rel
FUN  91141  91141          1'091'888  1'640             flockfile
FUN  91141  91141          1'092'624  1'656               _pthread_mutex_lock
FUN  91141  91141          1'093'344  1'672                 pthread_mutex_lock_impl
FUN  91141  91141          1'094'112  1'736                   nsync_mu_lock
FUN  91141  91141          1'094'848  1'768                     __aarch64_cas4_acq
FUN  91141  91141          1'095'680  1'640             fflush_unlocked
FUN  91141  91141          1'096'464  1'640             funlockfile
FUN  91141  91141          1'097'168  1'656               _pthread_mutex_unlock
FUN  91141  91141          1'097'904  1'672                 pthread_mutex_unlock_impl
FUN  91141  91141          1'098'720  1'720                   nsync_mu_unlock
FUN  91141  91141          1'099'536  1'752                     __aarch64_cas4_rel
FUN  91141  91141          1'100'336  1'640             __stdio_lock
FUN  91141  91141          1'101'056  1'656               _pthread_mutex_lock
FUN  91141  91141          1'101'776  1'672                 pthread_mutex_lock_impl
FUN  91141  91141          1'102'544  1'736                   __aarch64_cas4_acq
FUN  91141  91141          1'103'296  1'640             __stdio_unref_unlocked
FUN  91141  91141          1'104'112  1'656               __stdio_unref_impl
FUN  91141  91141          1'104'848  1'720                 __aarch64_cas4_acq_rel
FUN  91141  91141          1'105'616  1'640             __stdio_unlock
FUN  91141  91141          1'106'320  1'656               _pthread_mutex_unlock
FUN  91141  91141          1'107'088  1'672                 pthread_mutex_unlock_impl
FUN  91141  91141          1'108'112  1'720                   __aarch64_ldadd4_rel
FUN  91141  91141          1'108'848  1'576           __cxa_lock
FUN  91141  91141          1'109'568  1'592             _pthread_mutex_lock
FUN  91141  91141          1'110'288  1'608               pthread_mutex_lock_impl
FUN  91141  91141          1'111'056  1'672                 __aarch64_cas4_acq
FUN  91141  91141          1'111'936  1'576           __cxa_unlock
FUN  91141  91141          1'112'672  1'592             _pthread_mutex_unlock
FUN  91141  91141          1'113'408  1'608               pthread_mutex_unlock_impl
FUN  91141  91141          1'114'176  1'656                 __aarch64_ldadd4_rel
FUN  91141  91141          1'114'928  1'512         _Exit
@trvv trvv added the medium severity Used to report medium severity bugs (e.g. Malfunctioning Features but still useable) label Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
medium severity Used to report medium severity bugs (e.g. Malfunctioning Features but still useable)
Projects
None yet
Development

No branches or pull requests

1 participant