Ok6410 Bare Metal Drive Learning (i) Development tools

Source: Internet
Author: User
Tags printable characters

1.GCC tool Chain

1.GCC file types processed by default

File type

Extended Name

Document description

Text file

*.c

C Language Source files

*. C, *.cxx, *.cc

C + + source files

*.i

Pre-processed C language source files

*.ii

Pre-processed C + + source files

*.S, *. S

Assembly

*.h

Header file

binary files

. o

Target file

. So

Dynamic Library

. A

Static Library

Table 1.GCC file types processed by default

GCC is a collection of tools, including preprocessor, compilers, assemblers, connectors, and so on.

2. Compiling tools and Binutils

The core of GCC is the compilation tool GCC, which compiles the C program, plus some binary tools.

Binutils is a collection of binary tools that contains assemblies, joins, and a range of ancillary tools.

L AS:GNU Assembler, which converts the assembly code of the processor into executable code and stores it in the target file. O

L LD:GNU Connector, used to combine one or more target files. O, libraries into one executable file, or generate static and dynamic libraries

L AR: Archive tool that can combine multiple files into one large file and can read the contents of the original file

L Strip: Remove the symbols from the file

L NM: Used to display symbols in the target file

L Objcopy: Tool for converting binary code

L Objdump: Disassembly tool for displaying target files

L Readelf: Displays various information in the Elf file

L String: Displays printable characters in the file

L Ranlib: Generate an index of the archive file and save it to the archive, and the index lists the re-provisioned target files defined by each member of the archive file.

L Addr2line: You can map the address of an executable program to the corresponding row of the source file

L Gprof: Displays various data of the program call segment

Figure 1: Program generation process using GCC

Use of 3.GCC Tools

    1. For programs that have only one source file, you can build the executable program in one step with GCC

GCC Main.c-o Main

    1. For programs that have multiple source files, you can also build an executable program in one step

GCC main.c hello.c init.c-o test

Options

Meaning

-C

Build the destination file only if you are not connected. O

-S

Compile-only assembler, generate assembly code

-E

Preprocessing only

-G

Include standard debugging information in an executable program

-O File

Output files to File

-V

Print out the command line information and compiler version of the compiler's internal compilation procedures

-I. Dir

Add dir directory to the list of header file search paths

-ldir

Add dir directory to the list of library file search paths

-static

Static compilation, do not use dynamic libraries, compiled programs larger

-L Library

Connect a library file named libraries

-W

Turn off all warnings

-wall

Allows all useful warning messages provided by GCC to be issued

-werror

Converts all warning messages to error messages and terminates the compilation process when a warning occurs

Table 2.GCC Common compilation options

4. Archiving Tools (AR) and static libraries

The generation of static library static libraries that can be generated using AR in GCC requires the target file, and the static library can be connected by the application

L Archive INIT.O and hello.o as a static library

AR-RV LIBTEST_S.A INIT.O hello.o

Option r means Insert module (replace) in library when the inserted module name already exists in the library, replace the module with the same name Option V is used to display additional information for the Execute Action option

L view content in a static library

Ar-t LIBTEST_S.A

L Delete a target file from a static library

Ar-d LIBTEST_S.A

L Connect static libraries when generating executable programs

Gcc-wall main.o-l. –ltest_s–o Testbylib

-L. Indicates that the containing current path is the search path,-ltest means a static library with a connection named LIBTEST_S.A or a dynamic library named libtest_s.so

5. Dynamic Library

The dynamic Lib can be generated using the GCC tool, and the dynamic library does not need to be connected to the executable program and does not increase the size of the executable when compared to the static library, but the dynamic inventory is required when running

L Generate commands for dynamic libraries

Gcc-shared-wall-g hello.o INIT.O libtest_d.so

6. Target file Replication (objcopy)

Objcopy is used to copy the contents of one target file into another target file, in fact objcopy is often used as a format conversion tool to convert the target file to a target file in another format

L Convert test to pure binary file

    • Objcopy test-o binary Test.bin

7. Target file information (objdump)

The target file Information tool Objdump can display the information of the file, can be used for various object files, library files, executable programs, after parsing the binary file, can obtain the header information and disassembly of the machine code

Objdump commonly used parameters are-r and-D. -D indicates that all assembly information is displayed in the file, and-R indicates the dynamic relocation entry for the display file.

L Disassemble binary files

    • Objdump-d hello.o
2.Makefile Engineering Management Tools

The composition of the 1.Makefile

    1. Rules

The most important ingredient in Makefile is the rule, which is used to illustrate how to generate the target file in the following format

Target:prerequisites

Command (the "tab" key in front of the command)

Target dependent commands

led.bin:led.o

Arm-linux-ld-tled.lds-o led.elf

    1. Pseudo target:

Makefile those that contain only the command, without any reliance on the goal becomes for the goal (phony targets)

. Phony:clean

Clean

RM–RF Hello main.o func.o

. Phony declare clean target as pseudo target

    1. Variable:

In makefile, users can define their own variables in addition to the default variables already defined in the system.

Variable

Describe

[Email protected]

Representing the target

$<

Represents the first dependent file

$^

On behalf of all dependent files

    1. Go back to display

The contents of the makefile after # are treated as comments

@ To cancel the Echo

Hello:hello.c

@gcc Hello.c-o Hello

    1. Example 1:

CC: = gcc

HEAD: = Hello.h init.h

SRC: = hello.c init.c main.c

OBJS: = hello.o init.o MAIN.O

TT: = Test

INC =.

CFLAGS =-pipe-g-wall-i$ (INC)

Ldflags =-wall-g

all:$ (TT)

$ (TT): $ (OBJS)

@echo "===== Build Standalone application: [email protected] ====="

$ (CC) $ (ldflags) $ (OBJS)-o [email protected]

MAIN.O:MAIN.C hello.h init.h

$ (CC) $ (CFLAGS)-C $<-o [email protected]

HELLO.O:HELLO.C hello.h

$ (CC) $ (CFLAGS)-C $<-o [email protected]

Init.o:init.c init.h

$ (CC) $ (CFLAGS)-C $<-o [email protected]

. Phony:clean

Clean

@echo "= = = Clean = = ="

Rm-f *.O

RM =f $ (TT)

    1. Example 2:

ALL:START.O MEM.O

Arm-linux-ld-tgboot.lds-o gboot.elf $^

Arm-linux-objcopy-o binary gboot.elf Gboot.bin

%.O:%. S

Arm-linux-gcc-g-C $^

%.O:%.c

Arm-linux-gcc-g-C $^

. Phony:clean

Clean

RM *.o *.elf *.bin

3. Connector scripts

1. Introduction

Ld:

GNU's linker.

Used to link a quantitative target file with the archive file and reposition their data, link symbol references.

When compiling a program, the final step is to run the LD to link

Each link is controlled by a link script that is written in the language of the link command.

2. Link Script

One of the main purposes of a linked script is to describe how each segment (data segment, code snippet, heap, Stack, BSS) in the input file is mapped to the output file and controls the memory layout of the output file.

The linker always uses a link script, and if you do not provide it, the linker will use a default script that is compiled into the linker executable file.

You can use the--verbose command line to display the contents of the default linker script.

You can use the-t command line to provide your own link script to replace the default link script.

3. Simple link Script example.

Many of the scripts are fairly straightforward.

Perhaps the simplest script contains only one command: ' SECTIONS '.

You can use ' SECTIONS ' to describe the memory layout of the output file.

' SECTIONS ' is a powerful command.

Suppose your program has only code snippets, initialized data segments, and uninitialized data segments. These will exist in '. Text ', ' Data ', ' BSS ' segments.

For this example, suppose the code should be loaded into the address 0x1000, and the data should start at 0x8000000, as follows: The script that implements this function

SECTIONS

{

. =0x1000;

. text:{* (. Text)}

. =0x8000000;

. data:{* (. Data)}

. bss:{* (. BSS)}

}

Specific analysis:

The keyword ' SECTIONS ' starts with this configuration. followed by a string of symbols placed in curly braces and the output description of the content.

The first line is to a special symbol '. ' Assignment, which is a positional identifier. If you do not otherwise make the address of the output segment, the address value is set to the existing value of the locator identifier, which is 0x1000.

The second line defines an output segment, '. Text '. Colon ': ' is the syntax required and can now be ignored. In the curly brackets after the segment, you should list all the names of the inputs that should be placed in the output segment. ' * ' is a wildcard character that matches all file names. The. Text fields in all input files are saved in this paragraph.

The rest is. Data and. BSS segments, in the same vein, the linker places all of the. Data segments from the beginning of the address 0x8000000.

Finally, the value of the locator identifier changes to 0x8000000 plus the address of all. Data segments. At this point the linker places all the. BSS addresses at the beginning.

4. Simple link Script command

Set entry point

When you run a program, the first instruction to be executed becomes the entry point. You can use the "ENTRY" link script command to set the entry point. The parameter is a symbolic name, as follows:

ENTRY (SYMBOL)

There are many different ways to set the entry point. The linker sets the entry point by trying the method in order, and if it succeeds, it stops.

1, '-E ' entry command-line options

2, the entry (SYMBOL) command in the link script

3, if start is defined, the value of start is used

4, if present, use the '. Text ' segment's first address

5, address ' 0 '

5, the command line set the link address

The LD is used to link multiple obj or so (library) files into an executable file.

Use the-t option to specify the data segment, the code snippet, and the starting position of the BSS segment. (-T is only used to link bootloader, kernels, and other software not supported by the underlying software.) When linking applications running on the operating system, the default link is generally used.

1, directly specify the code snippet, data segment, BSS segment start address

As follows:

-ttext startaddr

-tdata startaddr

-TBSS startaddr

For example:

Ld–ttext 0x00000000–g Led_on.o–o led_on_elf

2. Set the start address directly using the link script

Ld–ttimer.lds–o timer_elf A.O B.O

The link script timer.lds content is as follows:

sections{

. =0x30000000;

. Text: {* (. text)}

. Rodata ALIGN (4): {* (. rodata)}

. Data ALIGN (4): {* (. data)}

. BSS ALIGN (4): {*. (. BSS) * (COMMON)}

}

A sections command contains one or more segments, which is the basic unit of a connection script that represents how a part of the input file is placed.

Full link Script

Output_arch (ARM)

ENTRY (_start)

SECTIONS {

. = 0x50008000;

. = ALIGN (4);

. Text:

{

START.O (. Text)

* (. Text)

}

. = ALIGN (4);

. Data:

{

* (. Data)

}

. = ALIGN (4);

Bss_start =.;

. BSS:

{

* (. BSS)

}

Bss_end =.;

}

Ok6410 Bare Metal Drive Learning (i) Development tools

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.