Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Melzzzzz <mel@zzzzz.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: [clang] -Os invalid content of argc+argv |
| Date | 2015-09-03 23:31 +0200 |
| Organization | albasani.net |
| Message-ID | <20150903233124.38258cdb@maxa-pc> (permalink) |
| References | <68a9e68b-dc3b-4c5e-8d01-bc91daaeb0f2@googlegroups.com> |
On Thu, 3 Sep 2015 13:28:33 -0700 (PDT)
m.labanowicz@gmail.com wrote:
> Hello,
>
> I have found an unexpected result of application compiled with clang.
>
> 'argc' + 'argv' values are incorrect.
>
> Main conditions where issue is observed:
> a) compilation under system: Windows 10 + Cygwin64
> (Ubuntu.14.04.64bit on the same machine issue is not observed)
> b) enabled optimisation for size flag: -Os
> c) clang or clang++ compilator
> (not observed with gcc/g++)
>
> Following is an example that demonstrates the issue:
>
> --{example:beg}--------------------------------------
>
> # gawk '{printf("/*%04d*/ %s\n", NR, $0);}' main.c
> /*0001*/ #include <stdio.h>
> /*0002*/ #include <stdlib.h>
> /*0003*/ #ifdef __cplusplus
> /*0004*/ extern "C" {
> /*0005*/ #endif
> /*0006*/ int bar(int argc, char * argv [])
> /*0007*/ {
> /*0008*/ printf("argc=%d, argv=%p\n", argc, (void *)(argv));
> /*0009*/ if (argv) {
> /*0010*/ int i = 0;
> /*0011*/ while (argv[i]) {
> /*0012*/ printf("argv[%d] = %p", i, (void *)(argv[i]));
> /*0013*/ if (argv[i]) {
> /*0014*/ printf(" = \"%s\"", argv[i]);
> /*0015*/ }
> /*0016*/ printf("\n");
> /*0017*/ ++i;
> /*0018*/ }
> /*0019*/ }
> /*0020*/ return EXIT_SUCCESS;
> /*0021*/ }
> /*0022*/ int main(int argc, char * argv [])
> /*0023*/ {
> /*0024*/ return bar(argc, argv);
> /*0025*/ }
> /*0026*/ #ifdef __cplusplus
> /*0027*/ }
> /*0028*/ #endif
>
> # gcc --version && gcc -Os main.c -o a.exe && ./a.exe 1 2 3
> gcc (GCC) 4.9.3
> Copyright (C) 2015 Free Software Foundation, Inc.
> This is free software; see the source for copying conditions. There
> is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
> PARTICULAR PURPOSE.
>
> argc=4, argv=0x24cb50
> argv[0] = 0x18032a770 = "./a"
> argv[1] = 0x18032b7b8 = "1"
> argv[2] = 0x18032b808 = "2"
> argv[3] = 0x18032b7e0 = "3"
>
> # g++ --version && g++ -Os main.c -o a.exe && ./a.exe 1 2 3
> g++ (GCC) 4.9.3
> Copyright (C) 2015 Free Software Foundation, Inc.
> This is free software; see the source for copying conditions. There
> is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
> PARTICULAR PURPOSE.
>
> argc=4, argv=0x24cb50
> argv[0] = 0x18032a770 = "./a"
> argv[1] = 0x18032b7b8 = "1"
> argv[2] = 0x18032b808 = "2"
> argv[3] = 0x18032b7e0 = "3"
>
> # clang --version && clang -Os main.c -o a.exe && ./a.exe 1 2 3
> clang version 3.5.2 (tags/RELEASE_352/final)
> Target: x86_64-unknown-windows-cygnus
> Thread model: posix
> argc=1, argv=0x0
>
> # clang++ --version && clang++ -Os main.c -o a.exe && ./a.exe 1 2 3
> clang version 3.5.2 (tags/RELEASE_352/final)
> Target: x86_64-unknown-windows-cygnus
> Thread model: posix
> clang: warning: treating 'c' input as 'c++' when in C++ mode, this
> behavior is deprecated argc=1, argv=0x0
>
> --{example:eof}--------------------------------------
>
> Is there any reasonable explanation of that ?
I don't know about cygwin but argc/argv values are parsed with crt
on Linux. That is if you link with c runtime and write main in assembler
you get already parsed values eg Linux passes values on stack but crt
parses them into rdi,rsi registers...
Probably on cygwin compiler parses those values therefore bug.
>
> Regards
>
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[clang] -Os invalid content of argc+argv m.labanowicz@gmail.com - 2015-09-03 13:28 -0700
Re: [clang] -Os invalid content of argc+argv Melzzzzz <mel@zzzzz.com> - 2015-09-03 23:31 +0200
Re: [clang] -Os invalid content of argc+argv Keith Thompson <kst-u@mib.org> - 2015-09-03 16:43 -0700
Re: [clang] -Os invalid content of argc+argv Melzzzzz <mel@zzzzz.com> - 2015-09-04 01:53 +0200
Re: [clang] -Os invalid content of argc+argv Philip Lantz <prl@canterey.us> - 2015-09-03 20:15 -0700
Re: [clang] -Os invalid content of argc+argv Keith Thompson <kst-u@mib.org> - 2015-09-04 09:15 -0700
Re: [clang] -Os invalid content of argc+argv m.labanowicz@gmail.com - 2015-09-04 10:33 -0700
Re: [clang] -Os invalid content of argc+argv Noob <root@127.0.0.1> - 2015-09-04 20:48 +0200
csiph-web