Japanese
FAQDevelopment environmentGNU development environment
BackForward
FAQ/Development environment

GNU development environment


I want to use kanji with gcc.

Q)
Is it possible to use kanji strings in comments etc. with gcc?

A)
Basically, kanji codes cannot be used. (Of course, it may pass in some cases.) However, in gcc SOA96/3/28 and later versions, you can use // comments as in C++ by default. If you use this, you won't have any problems using kanji.


About the assembly development environment in GNU.

Q)
I don't really understand how to create assembler routines and how to assemble them in the GNU environment.

A)
There are two main ways to develop using an assembler in the GNU environment, depending on the coding rules. Explaining each method,

1) Hitachi Assembler coding rules
Hitachi Assembler allows you to express data as strings, and allows you to specify ALIGN and SECTION in detail.
This coding rule allows you to use SHCASM codes as they are, so past assets can be used effectively.
To assemble sources written in this format, you need an IP creation tool, an AWK script included in the SBL6 package, an AWK program such as GAWK.EXE (awk on UNIX versions), and a batch file to start them. GASM.BAT (gasm.scr for UNIX) is required. These scripts convert Hitachi Assembler expressions into GNU AS assembly code, which can then be assembled using GNU AS.

2) GNU assembler coding rules
In GNU as, basic code is all lowercase. If you have experience developing with GNU as, I think this is better.
The invocation options are similar to gcc,

as -o object source -Iinclude -Ooptimizeflag

At SGI,

sh-as -o object source -Iinclude -Ooptimizeflag

Assemble it like this. You can also specify optimization etc. using the same method as gcc. Also, code written using this coding rule can be assembled directly from gcc.
For GNU as coding rules, please refer to the info file included with the gcc package, although it is in English.
How to read the info file:

info as

If you press the RET key at the item you want to read, a detailed explanation about that item will appear.


When compiling with gcc, an error occurs in go32.

Q)
When I try to compile the SGL sample program, it stops at the following location.Why?
Both GCC and SGL were downloaded from the internet, and the versions of SGL are 2.0A and GCC are from 10/26/95.

>C:\SGL\SAMPLE\S_2_2> make
>ld -Tsl.lnk -oformat srec -Map sl.map -e ___Start main.o polygon.o 
>../../lib/libsgl.a ../../lib/libgcc.a -o sl.s
>go32 version 1.12.maint1 Copyright (C) 1994 DJ Delorie
>Error:This program requires a version of go32(1.12.maint2) newer than 
>this one.
>make.exe: *** [sl.s] Error 1

A)
The following are the main causes:

  1. The version of go32.exe you are using is old.

  2. If you are using a Windows95 DOS window, this problem may occur depending on the property settings.


SBL cannot be compiled with gcc 3/28 version.

Q)
When I installed gcc from SGL TOOL KIT (April 30, 1996), the following error occurs when I run make. If you restore gccsh/ and below to the old version, this error will not occur.
I am using SBL instead of SGL for the library, is that related?

c:/gccsh/bin/../lib/libgcc.a(__main.o): In function `__do_global_dtors':
libgcc2.c(.text+0x2c): undefined reference to `__dtors'
libgcc2.c(.text+0x30): undefined reference to `__dtors_end'
c:/gccsh/bin/../lib/libgcc.a(__main.o): In function `__do_global_ctors':
libgcc2.c(.text+0x68): undefined reference to `__ctors_end'
libgcc2.c(.text+0x6c): undefined reference to `__ctors'
make.exe: *** [mltest.cof] Error 1

The version of gcc is

gcc driver version cygnus-2.7-96q1 SOA-960328 executing gcc version 
cygnus-2.7-96q1

is.

A)
Add the following segment to the link file (probably named saturn.lnk) linked with SBL.


.tors ALIGN(0x10) :
{
	___ctors = .;
	*(.ctors)
	___ctors_end = .;
	___dtors = . ;
	*(.dtors)
	___dtors_end = . ;
}

This is because C++ coding has been internally supported and symbol information has been added as GCC has been updated.

* .ctor is the C++ global constructor section, and .dtor is the C++ global destructor section.


Even if I increase the optimization of gcc, the speed does not increase.

Q)
When I run a program (approximately 40,000h) with the GCC compiler, whether the optimization level is set to 0 or 3, there seems to be no change in processing speed.
What could be the reason?
Other compile options except -O are the same as in the sample.

A)
For library-dependent code (that is, if the library has a large number of functions), optimizing it will probably not make much of a difference in speed or size.
Also, even if you use a lot of code other than the code to be optimized, you will not see much of an optimization effect.

A brief explanation of the optimization options that can be used with gcc is as follows:

-fthread-jumps:
Check whether the jump instruction jumps to another comparison instruction or branch whose result is already known, and set the address of the branch instruction instead of the comparison instruction address as the jump destination.

-fdefer-pop:
If there are multiple calls to functions that require PUSH on the stack, POP the stack by waiting for several function calls and performing them all at once.

-fcse-follow-jumps:
If the destination of the jump instruction is not passed by another path, follow the jump instruction and find it.

-fcse-skip-blocks:
Chases jump instructions that conditionally skip blocks.

-fexpensive-optimizations:
Optimizes with execution speed in mind.
This option primarily affects optimization options that are grouped together into multiple simple instructions.

-fstrength-reduce:
Generates code that uses as few loops as possible.

-finline:
Inline function calls whenever possible.

-fcaller-saves:
Eliminate redundant instructions to save register usage.

-freturn-cse-after-loop:
After loop optimization, we again remove similar code from the loop.

-fschedule-insns2:
After register allocation, instruction optimization is performed.

-fomit-frame-pointer:
Allows r14 to be used as a regular register when the frame pointer is not needed.

-funroll-loops:
Allows you to open and code for loops, etc.
More information, albeit in English, can be found in GCC's INFO file. Location,

gcc-> Invoking GCC-> Optimize Options

is. Please refer there.


Is there any good way to dump the error list emitted by gcc into a file?

Q)
When a compile error occurs, I would like to redirect the error information and use it for tag jumps on the editor, but it seems that the error is output to stderr instead of stdout, so I can't write it to a file.
If possible, I would appreciate it if you could change the information such as the file and line number where the error occurred to be output to stdout.

A)
It is true that tools created in UNIX environments such as gcc often output errors to STDERR, so the output cannot be redirected in environments such as DOS.
However, if you set the parameter 2r1 to the GO32 environment variable, both STDERR and STDOUT output will be output to STDOUT, so you can redirect error output.
Specifically, SATURN\GCCSH\SETENV.BAT

GO32=...

part of

GO32=2r1

Please. (The EMM part is only required if the CPU is 386 or less.) Another solution is to use the gcc option,

-Wno-*

You can limit the output of error messages using the following.
For more information on this option, please see the article about Gcc's Invoking using the info command.


I want to set sections for variables and functions.

Q)
I would like to arbitrarily assign SECTION to functions and variables in the gcc environment, but how should I do this?

A)
In the gcc environment, SECTION can be specified for each function or variable. (It is not possible to put part of the code within a function in a separate section.)
To explain how to do it, declare the functions and variables as follows.

Type declarator symbol __attribute__ ((section ("section name")));

for example,

char stack[10000] __attribute__ ((section ("STACK")));
int flag __attribute__ ((section ("COMMON"))) = 10;
void ExpandData( void ) __attribute__ ((section ("Overlay")));

Also, this section name must be defined when linking.
Regarding section declaration at link time, generally:

'sl.lnk' for SGL
'saturn.lnk' for SBL

It is contained in the file.
If you need to specify a new section, you should add the new section using this file as a reference.


I want to enter long commands from the command line.

Q)
I want to enter long commands from the command line.

A)
GCC supports so-called "subcommand files".

gcc ilename...

This allows GCC to read command line options from a file.


I want to use an inline assembler in a C function.

Q)

A)
Instead of defining inline assemblers using "__asm__" , define them using "_asm_volatile" .
This prevents you from optimizing or removing inline assemblers.

GCC is known to return incorrect results when optimizing non-volatile inline assemblers.
Also, if you forget the two colons separating register constraints at the end of an inline assembler fragment, GCC will usually crash. Even if your inline assembler does not have register constraints, be sure to include two colons.

GCC allows inline assembler sections to be placed outside functions, so it is possible to create routines written entirely in assembler in the C source.
When using assembly outside of C functions, ignore the "volatile" keyword as it only confuses the compiler.

* Inline assembler written outside functions in C source cannot be debugged at the source level. - If you want to write large-sized assembly code, we recommend creating a separate assembly file.
This will probably allow you to properly debug at the source level.


GCC returns the message "garbage at end of number".

Q)
When compiling with gcc, I get the error message "garbage at end of number".
When does this happen?

A)
Have you written something like this?

"0x1800E+OFFSET"

GCC interprets this as a floating point number because the "0E+OFFSET" part looks like a floating point number.
To prevent this, put a space between "E" and "+".


I want to use a divider using gcc.

Q)
I heard that gcc does not normally generate code that uses a divider, but how can I generate code that uses a divider?

A)
SH2 has a parallel divider that operates with 39 clocks. GCC does not use this divider.
Below are two examples of macros to easily use the divider.

For C:

/*
** void Set_Hardware_Divide(int, int);
**
** Set the dividend and divisor of the hardware divide unit.
** The divider requires 37 clocks to calculate a result,
** so you want to execute some other code before retrieving the result.
*/
#define Set_Hardware_Divide(x,y) \
  ({ \ 
     int *div_unit = (int *)0xffffff00; \ 
     int dividend = x, divisor = y; \ 
     __asm__ volatile ("mov.l %0,@(4,%2); mov.l %1,@%2" \ 
       : /* no output */ \ 
       : "r" (dividend), "r" (divisor), "r" (div_unit)); \ 
  });
/*
** int Get_Hardware_Divide(void)
**
** Retrieves division result from the hardware divide unit.
** If less than 37 clocks have elapsed the CPU will be halted
** until the result is ready.
*/
#define Get_Hardware_Divide() \
  ({ \ 
    int *div_unit = (int *)0xffffff00; \
    int __result; \
    __asm__ volatile ("mov.l @(0x1c,%1),%0" \
      : "=r" (__result) \ 
      : "r" (div_unit)); \ 
    __result; \ 
  });

To perform a division operation, you must call Set_Hardware_Divide.
While the divider is calculating, we execute some C code and then call Get_Hardware_Divide to get the result.
Make sure that both the mainline and interrupt programs do not use the divider.
If both the mainline program and the interrupt routine use a divider, the result of the mainline division will be rewritten, causing a very nasty bug that cannot be identified.
If the divider must be used both in the main line and in the interrupt code, the RAR and RSR that use the divider must be saved and restored in the interrupt process.

Using a divider is very risky because it uses the MAC register.

(Since dividers and multipliers are used inside SGL functions, there is a possibility that the MAC register will become inconsistent.) Please be careful about the state of the MAC register when using it. Technical Support cannot be held responsible for any instability or runaway behavior caused by using this feature.


I want to write code in C++.

Q)
I would like to code in C++.

A)
In conclusion, please do not include C++ code in SATURN programs.

for example,


int main(void)
{
  cout<< "hello, world";
}

The above program costs 448k in C++. Usually, C++ programs become extremely large due to the following two reasons.

  1. The code that is written is not effective.
  2. Importing a large library.


What are some efficient coding techniques?

Q)
Please tell me effective techniques when writing SATURN programs using gcc.

A)

1) Avoid code like this:

temp[index++] = a;
temp[index++] = b;
temp[index++] = c;

ANSI C tells us to update all variables at the end of the statement.
So the code created is

We are updating "index" with each statement.


temp[index] = a;
temp[index+1] = b;
temp[index+2] = c;
     index += 3;  

Another solution is to identify "index" as "register int".
There is no need to register index, but it is not executed directly from index. (Even if you write through the pointer, the value of index will not be rewritten.)

2) Using local variables
Using global variables is time consuming. - SH2 must run the following code to get the value.


mov.l L2,r1
mov.l @r1,r1

Local variables are less time consuming to use than global variables.
It is stack relative and the parameters are passed through the first four registers r4-r7 so it is faster.

3) If you want to shift to the right, use unsigned int.
SH2 does not have an arithmetic shift instruction to the right. Therefore, gcc creates large code to arithmetic shift a signed value to the right.
Please use a variable that can be arithmetic shifted to the right without a sign.

4) Write small functions.
Try not to use too many registers in a single function, as gcc will create disastrous code if it uses too many registers.
If you have a large function that takes more than 100 lines, please break it up into several smaller functions.


I would like to display a correspondence table between sources and assemblies.

Q)
I would like to be able to see the correspondence between C source and assembly when compiling with gcc. Is there any way to do this?

A)
Try compiling gcc with the -Wa,-ahl options.
A list of possible correspondences will be printed to standard output.
However, the source code will not be output unless -g is added as a compile option.

<< Example output > >
      gcc -g -O -Wa,-ahl main.c
                         :
        19:main.c        ****       j = 0xf000;
        77 004c D10E                  mov.l   L10,r1
        78 004e 9215                  mov.w   L14,r2
        79 0050 2121                  mov.w   r2,@r1
        21:main.c        ****     } else {
        81 0052 A003                  bra     L4
        82 0054 0009                  nop
        83                    L6:
                         :

Which make should I use?

Q)
An unexplained error occurs during Make.

A)
Basically, the Makefiles provided here are written for GNU Make.
If you try to run this using Microsoft Make or Boland Make, an incomprehensible error may occur.
Each Make has its own dialect and may differ slightly.


I want to create an original library.

Q)
Is there no librarian for gcc?

A)
The method to create a library in the GNU environment is as follows.

Create an object file.
Use the AR command included in the GNU package (sh-ar in the SGI environment) and write it as follows.

AR r userlib.a userobjs.o ...

userlib.a is the destination library file
userobjs.o is the object file you want to turn into a library.
This can be listed multiple times.
created with this command

ranlib userlib.a

Activate symbol information as (For the SGI version, use sh-ranlib instead of the ranlib command.)
The library created in this way can be used like any other library.
Also, if you want to add a new object to a library that has been compiled, you will need to unarchive it once . To unravel the archive,

ar x userlib.a

Add a new object to the output object file and repeat the above operations to complete a new library.


What is gasm?

Q)
We don't have gasm (GNU assembler?), which is used in the program makefle, but could you provide it?

A)
As you can see from the extension, gasm is a batch file, so by including this location in your path, gasm itself can be executed.
However, this batch file uses a script file for a pattern processing language called "awk" in the same directory to compile (assemble) the source file while processing it.
Regarding the PC version of awk, it is included in the SGL (4/30/96) version CD-ROM or the SBL posted on the technical information forum.
UNIX is a standard tool for the system, so there is no need to prepare anything else.


I get the error message "can't open blah: interrupted system call".

Q)
When I run LD on my PC

"can't open blah: interrupted system call"

An error message appears.

A)
There are not enough file descriptors. Add FILE=30 to CONFIG.SYS.


When I try to run LD on my PC, I get the error message "Not enough memory".

Q)
When I try to run LD on my PC, I get the error message "1Not enough memory".

A)
To see how much free memory is available for the DOS extender,

go32

Please type.
Reports how much RAM and SWAP space is available.
If you are using EMM386,

EMM386 AUTO

By doing so, you can convert XMS to EMS when necessary and increase the usable RAM capacity.


Linker is slow.

Q)
Linker is slow.

A)
Try using RAMdisk for temporary files.
Many people report that this dramatically reduces link times.


I want to disassemble object files and COFF files.

Q)
I would like to disassemble the contents of object files and COFF files without using a debugger.

A)
Use the command objdump (sh-objdump for IRIX).
For example, if you want to disassemble a COFF file,

objdump -d sl.cof

A disassemble list of sl.cof will be displayed.
However, in the case of binary data, information such as the start address is missing, so it cannot be disassembled.
For details on the objdump command, please see the attached information file.


I want to view symbol information of library files and COFF files.

Q)
I want to display the symbol map list of library files, COFF files, etc.

A)
Use nm (sh-nm for IRIX).

nm libsgl.a

If you do something like this, the symbol list for libsgl.a will be displayed.


BackForward
FAQDevelopment environmentGNU development environment
Copyright SEGA ENTERPRISES, LTD. 1997