FAQDevelopment environmentGNU development environment
BackForward
FAQ / Development environment

GNU development environment


I want to use Chinese characters with gcc.

Q)
Is it possible to use Chinese character strings for comments etc. with gcc?

A)
Basically, Kanji code cannot be used. (Of course, it may pass.) However, in gcc SOA96 / 3/28 and later versions, the same // comment as C ++ can be used by default. If you use this, it seems that there is no problem even if you use Chinese characters.


About the development environment for assembly in GNU.

Q)
I'm not sure how to create an assembler routine and how to assemble it in the GNU environment.

A)
Development in assembler under the GNU environment can be roughly divided into two methods depending on the coding rules. To explain each method,

1) Hitachi assembler coding rules
In Hitachi Assembler, data can be represented as a character string, and ALIGN and SECTION can be specified in detail.
As for this coding rule, the code in SHCASM can be used as it is, so past assets can be effectively utilized.
To assemble a source written in this format, use a tool for creating IP, AWK scripts such as AWK scripts and GAWK.EXE (awk in UNIX) included in the SBL6 package, and a batch file to start them. GASM.BAT (gasm.scr for UNIX) is required. These scripts allow you to convert the representation of Hitachi Assembler into assembly code in GNU AS and assemble it in GNU as.

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

as -o object source -Iinclude -Ooptimizeflag

At SGI,

sh-as -o object source -Iinclude -Ooptimizeflag

Assemble like this. You can also specify optimize etc. in the same way as gcc. Also, anything written with this coding rule can be assembled directly from gcc.
For GNU as coding rules, see the info file that comes with the gcc package, albeit in English.
How to read the info file

info as

Then, if you press the RET key at the item you want to read, a detailed explanation of that item will appear.


When compiling with gcc, I get an error with go32.

Q)
When I try to compile the SGL sample program, it stops at the following points. Why?
Both GCC and SGL are dropped from the net, and the version is 2.0A for SGL and 95/10/26 for GCC.

> 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 main causes are as follows.

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

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


SBL cannot be compiled with gcc 3/28 version.

Q)
When I installed gcc of SGL TOOL KIT (1996/4/30), I get the following error when making. If I revert the gccsh / and below to the old one, I don't get this error.
I'm using SBL instead of SGL for my library, is that relevant?

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 linked by SBL (probably named saturn.lnk).


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

This is because C ++ coding is internally supported and symbol information is added with the GCC version upgrade.

* .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)
With the GCC compiler, regardless of whether the optimization level is 0 or 3, when the program (about 40,000h) is executed, there seems to be no change in the processing speed.
What could be the reason?
Other compile options except -O are the same as the sample.

A)
For library-dependent code (that is, if you have a large number of library functions), you probably won't see much change in speed or size when you optimize.
Also, even if you use a lot of code other than the code to be optimized, the effect of optimization is not so much seen as a matter of course.

To briefly explain the optimization options that can be used with gcc,

-fthread-jumps:
Checks if the jump instruction jumps to another comparison instruction or branch whose result is already known, and makes the address of the branch instruction the jump destination of the jump instead of the address of the comparison instruction.

-fdefer-pop:
If there are multiple calls to the functions that require PUSH on the stack, the POP of the stack is performed after waiting for the calls of several functions.

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

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

-fexpensive-optimizations:
Optimize in consideration of execution speed.
This option mainly affects the kind of optimization options that can be combined into multiple simple instructions.

-fstrength-reduce:
It spits out code that doesn't use loops as much as possible.

-finline:
Inline function calls as much as possible.

-fcaller-saves:
Removes extra instructions to save register usage.

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

-fschedule-insns2:
After allocating the registers, the instructions are optimized.

-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.
The details are in English, but can be found in the GCC INFO file. Location,

gcc-> Invoking GCC-> Optimize Options

is. Please refer to that.


Is there any good way to put the error list that gcc spits out into a file?

Q)
I want to redirect the error information and use it for tag jump etc. on the editor when a compile error occurs, but it seems that the error is output to stderr instead of stdout, so I can not drop it in 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 so that it is output to stdout.

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

GO32 = ...

Part of

GO32 = 2r1

Please. (The EMM part is required only when the CPU is 386 or less.) Another countermeasure is the gcc option.

-Wno- *

You can use the kind of to limit the output of error messages.
For more information on this option, see the Gcc Invoking section on the info command.


I want to set a section for a variable or function.

Q)
I want to arbitrarily assign SECTION to functions and variables in the gcc environment. What should I do?

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

Type declarer 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 at the time of linking.
Generally speaking, when linking a section declaration

For SGL'sl.lnk'
For SBL'saturn.lnk'

It is contained in the file.
If you have to specify a new section, you need to add a new section by referring to this file.


I want to enter a long command from the command line.

Q)
I want to enter a long command 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 the inline assembler using "__asm__" , define it using "_asm_volatile".
This will prevent you from optimizing or removing the inline assembler.

GCC is known to return incorrect results when optimizing non-volatile inline assemblers.
Also, if you forget the two colons that separate the register constraints at the end of the inline assembler fragment, GCC usually crashes. Be sure to add two colons even if the inline assembler does not have a register constraint.

GCC allows you to put the inline assembler section outside the function, so you can create a routine written entirely in assembler in the C source.
Ignore the "volatile" keyword when using assemblies outside of C functions as it only misleads the compiler.

* Inline assembler written outside the function in C source cannot be debugged at the source level. --If you want to write large size assembly code, it is recommended to create a separate assembly file.
This will probably result in correct debugging at the source level.


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

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

A)
Isn't there a description 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 the "E" and the "+".


I want to use a divider with gcc.

Q)
I've heard that gcc usually doesn't generate code using a divider, but how can I generate code using a divider?

A)
SH2 has a parallel divider that operates on 39 clocks. GCC does not use this divider.
Here are two examples of macros that make it easy to 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; \ 
  });

You must call Set_Hardware_Divide to do the division process.
After executing some C code while the divider is doing the calculation, call Get_Hardware_Divide to get the calculation result.
Be careful not to use the divider for both the mainline and the interrupt program.
If both the mainline program and the interrupt routine use the divider, the result of the mainline division will be rewritten, resulting in a very annoying bug whose cause cannot be determined.
If you have to use the divider on both the mainline and the interrupt code, you need to save and restore the RAR and RSR that are using the divider on interrupt processing.

Using a divider is extremely dangerous because it uses MAC registers.

(Because the divider and multiplier are used inside the SGL function, the MAC register may become inconsistent.) Be careful about the state of the MAC register when using it. Technical support cannot be held responsible for any instability or runaway caused by using this function.


I want to write code in C ++.

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

A)
The bottom line is, don't put C ++ code in your SATURN program.

for example,


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

The above program can be as much as 448k in C ++. C ++ programs are usually tremendously large for two reasons:

  1. The code created is not effective.
  2. It takes in a large library.


What is an efficient coding technique?

Q)
Please tell me an effective technique when writing a SATURN program using gcc.

A)

1) Avoid code like the following:

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

ANSI C tells you to update all variables at the end of the statement.
Therefore, the created code is

"index" is updated with each statement.


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

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

2) Use of local variables
It takes time to use global variables. --SH2 must execute the following code to get the value.


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

Using local variables takes less time than global variables.
It is stack relative and the parameters are faster because it passes through the first four registers r4-r7.

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 a large code to arithmetically shift the signed value to the right.
Try to use a variable that can be arithmetically shifted to the right without a sign.

4) Write a small function.
Don't use too many registers in a function, as gcc will write disastrous code if you use too many registers.
Try to divide large functions that exceed a hundred lines into several smaller functions.


I want to show the correspondence table of source and assembly.

Q)
I want gcc to know the correspondence between C source and assembly at compile time. Is there any good way?

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

<< Output example >>
      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:
                         ::

Where should I use make?

Q)
I get an incomprehensible error when making.

A)
Basically, the Makefile provided here is written for GNU Make.
If you try to do this with Microsoft Make or Boland Make, you may get confusing errors.
Each Make has a dialect and may vary slightly.


I want to make an original library.

Q)
Is there a librarian for gcc?

A)
Here's how to create a library in the GNU environment.

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

AR r userlib.a userobjs.o ...

userlib.a is the destination library file
userobjs.o is the object file you want to make into a library.
This can be listed more than once.
What was created with this command

ranlib userlib.a

Activates the 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 the library once you have put it together, you need to unarchive it once. To solve the archive

ar x userlib.a

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


What is gasm?

Q)
I don't have gasm (GNU assembler?) Used in the program makefle here. Can you provide it?

A)
As you can see from the extension, gasm is a batch file, so you can execute gasm itself by passing this location through the path.
However, this batch file is compiled (assembled) while processing the source file using a script file for the pattern processing language called "awk" (oak) in the same directory.
The PC version of awk is included in the SGL (96/4/30) version of the CD-ROM or in the SBL posted on the Technical Information Forum.
UNIX is a standard system tool, so there is no need to prepare it again.


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

Q)
When you run LD on your PC

"can't open blah: interrupted system call"

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 an error message saying "Not enough memory".

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

A)
To see how much memory is available on the DOS extender

go32

Please type.
It 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 needed and increase the available RAM capacity.


The linker is slow.

Q)
The linker is slow.

A)
Try using a RAMdisk for temporary files.
There are many reports that this has dramatically reduced link time.


I want to disassemble object files and COFF files.

Q)
I would like to disassemble the contents of an object file or COFF file 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

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


I want to see the symbol information of a library file or COFF file.

Q)
I want to display a symbol map list such as a library file or COFF file.

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

nm libsgl.a

If so, the symbol list of libsgl.a will be displayed.


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