Compile errors?

B

BartC

David Brown said:
On 16/02/14 20:15, BartC wrote:
There are several parts that make up a toolchain - the compiler is only
one of them. gcc is a compiler that supports win64 directly, both as a
host and as a target. But the compiler itself is not sufficient to make
useful programs on a particular platform - for that, you need the
libraries, runtime, and headers for that platform's API and system
interfaces. gcc is the compiler - it does not provide these parts for any
target.

I disagree: the mingw gcc versions I've used seemed to contain things most
I need: windows.h for example, and the necessary libraries. I haven't needed
separate sets of headers and libraries. Otherwise I don't know what most of
the 12,000 files comprising mingw are for.
In addition, keeping up with Windows can be a tough game for a compiler -
things change every now and again. Sometimes that means changes need to
be made in the compiler itself.

Again I disagree. Until about 2012 I maintained my own language and
compilers for use under Windows. Very little maintenance was necessary
(around 2000 for example I upgraded to full 32-bit code generation; a bit
late, but I'd already been using mixed 32-bit/16-bit code since the 80386
appeared). Object code generation and linking had been offloaded to NASM at
some time during the nineties.
So when you download a "release" from mingw-64, it contains the libraries,
headers, and runtimes for using gcc on Win32 and Win64, along with any
useful outstanding patches to gcc itself. It does not contain the
compiler - you can download that and build it yourself, as this is a
source code release.

That's really what I'm trying to avoid. I have enough trouble compiling my
own applications, and the largest one I have is only a dozen modules,
neither does it have any circular dependencies as you'd get when compiling a
compiler with its own language (and what compiler version would be used to
compile it?). (I get enough of those sorts of headaches from working on my
own compilers which also compile themselves, and mine are tiny in
comparison.)

Using C was supposed to make life easier for me, not more difficult!

(I've just made a quick attempt to look at the gcc sources, but I got as far
as the file gcc-4.7.2-1-mingw32-src.tar.lzma, with a extension I have no
idea of (is there someone paid to keep thinking up new ones) and a size of
80MB. I don't need to know any more! Clearly trying to build just a huge
project is completely out of the question as I wouldn't have a clue. Writing
my own compiler - even a C compiler - would be far easier, and I'm being
serious!)
Alternatively, you could spend a couple of minutes reading the wiki and
find your way to the 64-bit binaries.

If you mean the wikipedia entries on mingw, that generates even more
confusion.

I think if gcc didn't have such a good optimiser (and was only so
ubiquitous), I would long ago have given up on it.
 
I

Ian Collins

BartC said:
I think if gcc didn't have such a good optimiser (and was only so
ubiquitous), I would long ago have given up on it.

Wouldn't it make more sense to give up on Windows?
 
E

Eric Sosman

[...]
Using C was supposed to make life easier for me, not more difficult!

If you'd avoid some of the practices you've shown in code
samples (e.g., those in this thread's original post) a few of
your difficulties with C might well abate ...

In another current thread you ask "How does anyone manage to
write any sizeable C project and keep multiple compilers happy at
the same time?" Part of the answer is "By knowing what the C
language does and doesn't specify, and sticking with the former."
 
B

BartC

Ian Collins said:
Wouldn't it make more sense to give up on Windows?

Actually, I'm trying to head in the general direction of Linux, but trying
to get my tools together first and at the moment they work on Windows. But
Linux has got its own problems too.

That doesn't change my point that gcc and its whole ecosystem seems vastly
bloated and over-complex. As I said I've written my own compilers and I know
things don't need to be that big or complicated to work! There are other
compilers too that are smaller and faster (in compilation effort, if not in
generated code speed).
 
D

David Brown

I disagree: the mingw gcc versions I've used seemed to contain things most
I need: windows.h for example, and the necessary libraries. I haven't
needed
separate sets of headers and libraries. Otherwise I don't know what most of
the 12,000 files comprising mingw are for.

That would be because what you downloaded from mingw was not just the
compiler, but the compiler along with a set of libraries, headers and
runtimes!

Note - the original "mingw" project provides headers, etc., that come
from MSDN. They are thus as close to being Windows standard headers as
you can get - and that means they are as limited as Windows/MSDN's C
support, which is barely up to C90 standards. Mingw-w64 has new
headers, etc., to give modern C standards support, including much of C11
(AFAIUI). So if you want to use modern C on Windows, mingw-w64 (or
related projects, like TDM) is the way to go.
Again I disagree. Until about 2012 I maintained my own language and
compilers for use under Windows. Very little maintenance was necessary
(around 2000 for example I upgraded to full 32-bit code generation; a bit
late, but I'd already been using mixed 32-bit/16-bit code since the 80386
appeared). Object code generation and linking had been offloaded to NASM at
some time during the nineties.

If you want to keep up with the latest possibilities with the latest
versions of windows, you need to update the tools to match. Of course,
it is often fine to stick to a limited set of features and be compatible
with a wider range of versions - in which case you don't need to update
often.
That's really what I'm trying to avoid. I have enough trouble compiling my
own applications, and the largest one I have is only a dozen modules,
neither does it have any circular dependencies as you'd get when
compiling a
compiler with its own language (and what compiler version would be used to
compile it?). (I get enough of those sorts of headaches from working on my
own compilers which also compile themselves, and mine are tiny in
comparison.)

Using C was supposed to make life easier for me, not more difficult!

(I've just made a quick attempt to look at the gcc sources, but I got as
far
as the file gcc-4.7.2-1-mingw32-src.tar.lzma, with a extension I have no
idea of (is there someone paid to keep thinking up new ones) and a size of
80MB. I don't need to know any more! Clearly trying to build just a huge
project is completely out of the question as I wouldn't have a clue.

The file here is a collection of source files, bundled together in a
tarball, and compressed with lzma - a compression format that gives very
good compression and high speed decompression, at the cost of low speed
compression. 7zip and peazip should handle it fine.
Writing
my own compiler - even a C compiler - would be far easier, and I'm being
serious!)


Having built gcc for a variety of targets (mostly embedded processors)
and three different hosts (Win32/mingw, 32-bit Linux and 64-bit Linux),
I can tell you it is /vastly/ easier than writing a compiler. It's a
weird concept when you first do it, but these days it is not much more
than the old ".configure && make && make install" process. Getting the
right libraries and headers is often the biggest challenge, and
mingw-w64 gives you that.

However, I agree that it is nice /not/ to have to build gcc yourself -
and it saves a chicken-and-egg problem when you want a native compiler
(though you can build a win64 host / win64 target gcc using win32 mingw
gcc, or using gcc on Linux). With a bit of poking around, I found
pre-build binaries within the files area of mingw-w64 - as well as on a
number of different sites. But mingw-w64 would be much improved with a
link on the front page saying "this is the current best pre-build binary
package".

If you mean the wikipedia entries on mingw, that generates even more
confusion.

I meant the mingw-w64 wiki.
I think if gcc didn't have such a good optimiser (and was only so
ubiquitous), I would long ago have given up on it.

gcc - in any form - does not fit in well with the "windows way". Linux
developers are typically happy with command-line compilers, Makefiles,
etc., but Windows developers often expect point-and-click interfaces,
and wizards and dialogs for compiler setup. Tools like Code Blocks are
often a better choice for Windows than bare-bones gcc, as they come with
an IDE, debugger, libraries, etc., as well as the compiler itself.
Currently, Code Blocks only comes with 32-bit gcc for Windows (AFAIK),
though it supports 64-bit if you have it installed.

Of course, the real question is if you /need/ 64-bit gcc for Windows.
It will not be significantly faster for most code, unless your code
makes heavy use of 64-bit maths - on "typical" code the extra speed
comes from the additional registers in 64-bit mode, and is offset by the
slowdown of 64-bit pointers. (Of course, if your code needs more than 3
GB memory, you want 64-bit code.)
 
G

Geoff

It doesn't include the actual compiler, afaics, unless it's very well
hidden. (Actually I have little idea exactly what this product is for.)

You'd think they would make it more obvious *and* put a very clear link to
the corresponding 64-bit gcc compiler. But the official mingw gcc release
4.8.1, when you eventually make your own way to it, doesn't support 64-bit
code generation. This is something that you have to discover for yourself
however.

It looks like you installed it wrong.

I downloaded the installer from:
http://sourceforge.net/projects/mingwbuilds/?source=recommended

I then ran the installer, selected the x64 architecture in the
installer dialog and installed it into my system with the following
result:

C:\Users\Geoff\Documents\tlimits>gcc -m64 tlimits.c

C:\Users\Geoff\Documents\tlimits>a.exe
CHAR_BIT = 8 MB_LEN_MAX = 5

CHAR_MAX = 127 CHAR_MIN = -128
SCHAR_MAX = 127 SCHAR_MIN = -128
UCHAR_MAX = 255

SHRT_MAX = 32767 SHRT_MIN = -32768
USHRT_MAX = 65535

INT_MAX = 2147483647 INT_MIN = -2147483648
UINT_MAX = 4294967295

LONG_MAX = 2147483647 LONG_MIN = -2147483648
ULONG_MAX = 4294967295

LLONG_MAX = 9223372036854775807 LLONG_MIN = -9223372036854775808
ULLONG_MAX = 18446744073709551615

SUCCESS testing <limits.h>
 
I

Ian Collins

BartC said:
Actually, I'm trying to head in the general direction of Linux, but trying
to get my tools together first and at the moment they work on Windows. But
Linux has got its own problems too.

There are plenty of alternatives to Linux.
That doesn't change my point that gcc and its whole ecosystem seems vastly
bloated and over-complex. As I said I've written my own compilers and I know
things don't need to be that big or complicated to work! There are other
compilers too that are smaller and faster (in compilation effort, if not in
generated code speed).

Over so many platforms including cross-compilers and with as many
languages? The GNU compiler suite has probably grown to be that complex
out of necessity.
 
D

David Brown

Actually, I'm trying to head in the general direction of Linux, but
trying to get my tools together first and at the moment they work on
Windows. But Linux has got its own problems too.

That doesn't change my point that gcc and its whole ecosystem seems
vastly bloated and over-complex. As I said I've written my own compilers
and I know things don't need to be that big or complicated to work!
There are other compilers too that are smaller and faster (in
compilation effort, if not in generated code speed).

There are certainly other compilers that are smaller, but none that are
smaller and have comparable features. There are other compilers that
compile faster, but none that are noticeably faster while generating as
good code. There are other compilers that generate faster object code,
but none that generate /significantly/ faster object code, and none that
do it with less complexity and greater compilation speed.

There are always trade-offs in compiler design. gcc has enormous
functionality - it has some of the best support for modern language
standards, includes a range of extensions, supports several different
programming languages, runs on a dozen different hosts, generates code
for something like 40 different target processors, and generates some of
the best optimised object code available. Of course it is big and
complicated!

There is no doubt that /some/ of that complication is historic - gcc
evolved to its current state, rather than being designed for such
flexibility from its beginnings. But the only comparable compiler which
/was/ designed for flexibility, llvm, is also big and complex.
 
D

David Brown

One (early) study showed that SPEC results are, on average, 7% higher in
64-bit mode vs 32-bit mode, but the results for individual tests vary
from -26% to +35%, depending on the relative impact of more/wider
registers vs. larger pointers for a given workload.

http://www.ece.neu.edu/groups/nucar/publications/SWC06.pdf

Yes, all you can say for sure is that results will vary. But generally,
unless you have an application that significantly benefits from 64-bit
mode features, it is probably not worth switching to 64-bit just for speed.

They also vary a bit between platforms, apparently - while Linux and
Windows share the same basic calling convention for 32-bit, and generate
very similar object code from the same compiler, there are more
differences in the 64-bit world as Linux has a more efficient calling
convention.
 
J

jacob navia

Le 17/02/2014 08:48, David Brown a écrit :
There are other compilers that generate faster object code,
but none that generate /significantly/ faster object code, and none that
do it with less complexity and greater compilation speed.

You have never used Intel's compiler.
 
J

jacob navia

Le 17/02/2014 08:52, David Brown a écrit :
They also vary a bit between platforms, apparently - while Linux and
Windows share the same basic calling convention for 32-bit, and generate
very similar object code from the same compiler, there are more
differences in the 64-bit world as Linux has a more efficient calling
convention.

You are confusing "more complex" with "more efficient". Actually they
are not the same. A complex calling convention as in LInux doesn't mean
higher speed. Under windows only four arguments are passed in registers,
what caters for the great majority of functions. Under Linux, there are
more registers used, but linux has fewer registers that are saved from
function call to function call.

In general you do not know windows (as you yourself say) so it is not a
good idea trying to speak about things you do not understand.
 
B

BartC

It looks like you installed it wrong.
I downloaded the installer from:
http://sourceforge.net/projects/mingwbuilds/?source=recommended

I then ran the installer, selected the x64 architecture in the
installer dialog and installed it into my system with the following
result:

Thanks. But it says: "Installing MinGW-builds: Cannot download
repository.txt".

Besides this is unlike any other thing I've tried to download, and I don't
think that changes my conclusion that whatever the mingw-w64 was that I
downloaded, it didn't include an actual compiler. The fact that there are so
many different sources, different builds and installers and sites and
everything, is one of the things that makes it all so complicated.
C:\Users\Geoff\Documents\tlimits>gcc -m64 tlimits.c

C:\Users\Geoff\Documents\tlimits>a.exe
CHAR_BIT = 8 MB_LEN_MAX = 5

CHAR_MAX = 127 CHAR_MIN = -128
SCHAR_MAX = 127 SCHAR_MIN = -128
UCHAR_MAX = 255

SHRT_MAX = 32767 SHRT_MIN = -32768
USHRT_MAX = 65535

INT_MAX = 2147483647 INT_MIN = -2147483648
UINT_MAX = 4294967295

LONG_MAX = 2147483647 LONG_MIN = -2147483648
ULONG_MAX = 4294967295

LLONG_MAX = 9223372036854775807 LLONG_MIN = -9223372036854775808
ULLONG_MAX = 18446744073709551615

SUCCESS testing <limits.h>

I'm not sure that that indicates this is actual 64-bit code (it probably is,
if you used -m64 and it didn't complain); I suspect you'd get the same
values with -m32. UINTPTR_MAX is a better indicator.
 
D

David Brown

Le 17/02/2014 08:48, David Brown a écrit :

You have never used Intel's compiler.

I have used it on occasion, but not much. For some code, it can
generate significantly faster object code than gcc, especially when you
can take advantage of its better maths libraries and better support for
Intel cpu vector operations. But for most code, there is not a great
deal of difference - and gcc is often faster (especially on non-Intel
cpus, oddly enough). It is also a big and complex compiler, and
compilation takes time.

Of course icc is a fine compiler. All I am really trying to say is that
if you want a powerful compiler with a lot of features and solid
optimisation, then the compiler is going to be large, complicated, and
take time to run. Intel's compiler is no exception.
 
B

BartC

David Brown said:
On 16/02/14 23:55, BartC wrote:
gcc - in any form - does not fit in well with the "windows way". Linux
developers are typically happy with command-line compilers, Makefiles,
etc., but Windows developers often expect point-and-click interfaces, and
wizards and dialogs for compiler setup.

Maybe. But the basic, underlying tools often have command-line interfaces (I
vaguely remember CL.EXE for MS' C compiler, and there is CSC.EXE for their
C# compiler. In fact all C compilers I've tried under Windows, including
gcc, have command-line interfaces (and I used these to build into my own
IDE)). So that is an irrelevant point. For the actual installation and
setup, I don't care how it works provided it does work.
Of course, the real question is if you /need/ 64-bit gcc for Windows. It
will not be significantly faster for most code, unless your code makes
heavy use of 64-bit maths - on "typical" code the extra speed comes from
the additional registers in 64-bit mode, and is offset by the slowdown of
64-bit pointers. (Of course, if your code needs more than 3 GB memory,
you want 64-bit code.)

Well, that is what I intend to find out. I'm not writing 'most code', but
have my bytecode interpreter in mind.

I know that, from the point of view of writing x64 ASM code, this would
likely benefit from 64-bit load/store operations, 64-bit registers instead
of 32-bit, and the extra 64-bit registers, *if* I can keep the underlying
data structures the same size. I might even add some extra 'register'-based
bytecode ops, instead of stack-based, if they can be used advantageously.

But I also know that if I just blindly recompile the C sources I have now,
it's unlikely to be any faster, and could be slower. But I'm trying to get
to that point first!

(Not the best processor design in x64; I think there is less demand for
64-bit addressing than for 64-bit data, registers and operations. But the
former demands 64-bit pointers which are often unnecessary and will slow
things down.)
 
D

David Brown

Le 17/02/2014 08:52, David Brown a écrit :


You are confusing "more complex" with "more efficient". Actually they
are not the same. A complex calling convention as in LInux doesn't mean
higher speed. Under windows only four arguments are passed in registers,
what caters for the great majority of functions. Under Linux, there are
more registers used, but linux has fewer registers that are saved from
function call to function call.

And I gather the major difference is about stack allocation in the
calling convention, rather than the number of parameters (I agree that
not many functions use more than four parameters). It is the Win64
calling convention that is more complex, however, as it requires the
caller to allocate 32 bytes of "shadow space" on the stack before
calling a function - whether or not that space is ever used. On Linux,
there is no such requirement - functions allocate stack space if and
when they need it (and apparently leaf functions can use 128 bytes of
stack space "for free").

Linux uses the x86-64 calling convention designed by AMD and Intel as
their standard ABI, aimed to be most efficient general calling
convention they could make. Win64 uses an odd calling convention based
on their own ideas, and different from everybody else. I don't really
know why the did this - perhaps there are compatibility reasons somewhere.

So yes, I think the Linux x86-64-bit calling convention is more
efficient than the Windows one.
In general you do not know windows (as you yourself say) so it is not a
good idea trying to speak about things you do not understand.

Fair enough, I suppose - my "testimony" is hearsay, and based on things
I have read rather than my own testing. I use Windows regularly, but my
Windows programming is more often Python than C and I have not done any
sort of comparisons. My guess is that there will not be a big
difference in speed due to the calling conventions, and in most cases it
will be swamped by other factors.
 
J

jacob navia

Le 17/02/2014 11:27, David Brown a écrit :
And I gather the major difference is about stack allocation in the
calling convention, rather than the number of parameters (I agree that
not many functions use more than four parameters). It is the Win64
calling convention that is more complex, however, as it requires the
caller to allocate 32 bytes of "shadow space" on the stack before
calling a function - whether or not that space is ever used. On Linux,
there is no such requirement - functions allocate stack space if and
when they need it (and apparently leaf functions can use 128 bytes of
stack space "for free").

Adding 32 bytes of stack space is not really anything complex!
That space is required to save the values of the 4 registers that hold
the arguments in case it is needed to save them. Nothing really
extraordinary!

Linux uses the x86-64 calling convention designed by AMD and Intel as
their standard ABI, aimed to be most efficient general calling
convention they could make. Win64 uses an odd calling convention based
on their own ideas, and different from everybody else. I don't really
know why the did this - perhaps there are compatibility reasons somewhere.

Excuse me but Intel did not say anything about calling conventions that
is a myth. And there were NO compatibility reasons either because 64 bit
code is completely different than 32 bit code because there are 8 new
registers, and (at last) the possibility of using the registers to pass
arguments.
So yes, I think the Linux x86-64-bit calling convention is more
efficient than the Windows one.


There is no basis for that but keep your opinion if you wish. I agree
that we disagree.
Fair enough, I suppose - my "testimony" is hearsay, and based on things
I have read rather than my own testing. I use Windows regularly, but my
Windows programming is more often Python than C and I have not done any
sort of comparisons. My guess is that there will not be a big
difference in speed due to the calling conventions, and in most cases it
will be swamped by other factors.

Exactly
 
M

Melzzzzz

Le 17/02/2014 11:27, David Brown a écrit :


Adding 32 bytes of stack space is not really anything complex!

It is, if one needs to keep stack 16 bytes aligned ;)
That space is required to save the values of the 4 registers that
hold the arguments in case it is needed to save them. Nothing really
extraordinary!

What it is useful for (except for debugging)?
 
J

jacob navia

Le 17/02/2014 12:31, Melzzzzz a écrit :
It is, if one needs to keep stack 16 bytes aligned ;)

???

Excuse me but you didn't notice that 32 is a multiple of 16?

If your stack is 16 byte aligned, adding 16, 32, 48, 64 etc does NOT
change anything.

But maybe this is too complex for you?
:)
What it is useful for (except for debugging)?

Debugging is not really important of course. Only bad programmers have
bugs, and they are all under windows. Linux programmers are bug free.
 
K

Kenny McCormack

jacob navia said:
Excuse me but Intel did not say anything about calling conventions that
is a myth.

Did anyone claim that anything Intel said was mythological?
 
K

Kenny McCormack

jacob navia said:
In general you do not know windows (as you yourself say) so it is not a
good idea trying to speak about things you do not understand.

They love to do that in this group. Say things like: I don't know anything
about Windows (because I'm a hip Unix dude, doncha know - and Windows is
just so ... for the masses, doncha know...!), but ... (and then procede to
pontificate about something having to do with Windows).

(My take on this follows)
As Tom Lehrer said: If people can't communicate, the very least they could
do is to ... shut up!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,075
Messages
2,570,562
Members
47,197
Latest member
NDTShavonn

Latest Threads

Top