在u-boot下,定义变量,

编译,编译完后  使用arm-linux-nm arm    没有去头的二进制可执行文件

  都在BSS段,均为初始化。

打印之后会出算随机值。

  目前还处于uboot阶段,如果在根文件系统的话,加载器把二进制可执行文件加载到内存,并将BSS段清零。    放在BSS段的变量所对应的空间,在二进制可执行文件中不占空间。放在Data段才分配空间。

ld --help

  

默认链接脚本:arm-linux-ld -verbose

 GNU ld (GNU Binutils) 2.20.1.20100303
Supported emulations:
armelf_linux_eabi
armelfb_linux_eabi
using internal linker script:
==================================================
/* Script for -z combreloc: combine and sort reloc sections */
OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm",
"elf32-littlearm")    //小端存储的arm
OUTPUT_ARCH(arm)
ENTRY(_start)
SEARCH_DIR("=/usr/local/lib"); SEARCH_DIR("=/lib"); SEARCH_DIR("=/usr/lib");
SECTIONS
{
/* Read-only sections, merged into text segment: */
PROVIDE (__executable_start = SEGMENT_START("text-segment", 0x00008000)); . = SEGMENT_START("text-segment", 0x00008000) + SIZEOF_HEADERS;
.interp : { *(.interp) }
.note.gnu.build-id : { *(.note.gnu.build-id) }
.hash : { *(.hash) }
.gnu.hash : { *(.gnu.hash) }
.dynsym : { *(.dynsym) }
.dynstr : { *(.dynstr) }
.gnu.version : { *(.gnu.version) }
.gnu.version_d : { *(.gnu.version_d) }
.gnu.version_r : { *(.gnu.version_r) }
.rel.dyn :
{
*(.rel.init)
*(.rel.text .rel.text.* .rel.gnu.linkonce.t.*)
*(.rel.fini)
*(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*)
*(.rel.data.rel.ro* .rel.gnu.linkonce.d.rel.ro.*)
*(.rel.data .rel.data.* .rel.gnu.linkonce.d.*)
*(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*)
*(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*)
*(.rel.ctors)
*(.rel.dtors)
*(.rel.got)
*(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*)
PROVIDE_HIDDEN (__rel_iplt_start = .);
*(.rel.iplt)
PROVIDE_HIDDEN (__rel_iplt_end = .);
PROVIDE_HIDDEN (__rela_iplt_start = .);
PROVIDE_HIDDEN (__rela_iplt_end = .);
}
.rela.dyn :
{
*(.rela.init)
*(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)
*(.rela.fini)
*(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)
*(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)
*(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)
*(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)
*(.rela.ctors)
*(.rela.dtors)
*(.rela.got)
*(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)
PROVIDE_HIDDEN (__rel_iplt_start = .);
PROVIDE_HIDDEN (__rel_iplt_end = .);
PROVIDE_HIDDEN (__rela_iplt_start = .);
*(.rela.iplt)
PROVIDE_HIDDEN (__rela_iplt_end = .);
}
.rel.plt :
{
*(.rel.plt)
}
.rela.plt :
{
*(.rela.plt)
}
.init :
{
KEEP (*(.init))
} =
.plt : { *(.plt) }
.iplt : { *(.iplt) }
.text :
{
*(.text.unlikely .text.*_unlikely)
*(.text .stub .text.* .gnu.linkonce.t.*)
/* .gnu.warning sections are handled specially by elf32.em. */
*(.gnu.warning)
*(.glue_7t) *(.glue_7) *(.vfp11_veneer) *(.v4_bx)
} =
.fini :
{
KEEP (*(.fini))
} =
PROVIDE (__etext = .);
PROVIDE (_etext = .);
PROVIDE (etext = .);
.rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) }
.rodata1 : { *(.rodata1) }
.ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) }
__exidx_start = .;
.ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) }
__exidx_end = .;
.eh_frame_hdr : { *(.eh_frame_hdr) }
.eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) }
.gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) }
/* Adjust the address for the data segment. We want to adjust up to
the same address within the page on the next page up. */
. = ALIGN (CONSTANT (MAXPAGESIZE)) - ((CONSTANT (MAXPAGESIZE) - .) & (CONSTANT (MAXPAGESIZE) - )); . = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE));
/* Exception handling */
.eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) }
.gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }
/* Thread Local Storage sections */
.tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) }
.tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) }
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);
}
.init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array))
PROVIDE_HIDDEN (__init_array_end = .);
}
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(.fini_array))
KEEP (*(SORT(.fini_array.*)))
PROVIDE_HIDDEN (__fini_array_end = .);
}
.ctors :
{
/* gcc uses crtbegin.o to find the start of
the constructors, so we make sure it is
first. Because this is a wildcard, it
doesn't matter if the user does not
actually link against crtbegin.o; the
linker won't look for a file to match a
wildcard. The wildcard also means that it
doesn't matter which directory crtbegin.o
is in. */
KEEP (*crtbegin.o(.ctors))
KEEP (*crtbegin?.o(.ctors))
/* We don't want to include the .ctor section from
the crtend.o file until after the sorted ctors.
The .ctor section from the crtend file contains the
end of ctors marker and it must be last */
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*(.ctors))
}
.dtors :
{
KEEP (*crtbegin.o(.dtors))
KEEP (*crtbegin?.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*(.dtors))
}
.jcr : { KEEP (*(.jcr)) }
.data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro* .gnu.linkonce.d.rel.ro.*) }
.dynamic : { *(.dynamic) }
. = DATA_SEGMENT_RELRO_END (, .);
.got : { *(.got.plt) *(.igot.plt) *(.got) *(.igot) }
.data :
{
PROVIDE (__data_start = .);
*(.data .data.* .gnu.linkonce.d.*)
SORT(CONSTRUCTORS)
}
.data1 : { *(.data1) }
_edata = .; PROVIDE (edata = .);
__bss_start = .;
__bss_start__ = .;
.bss :        //找到了
{
*(.dynbss)
*(.bss .bss.* .gnu.linkonce.b.*)
*(COMMON)
/* Align here to ensure that the .bss section occupies space up to
_end. Align after .bss to ensure correct alignment even if the
.bss section disappears because there are no input sections.
FIXME: Why do we need it? When there is no .bss section, we don't
pad the .data section. */
. = ALIGN(. != ? / : );
}
_bss_end__ = . ; __bss_end__ = . ;
. = ALIGN( / );
. = ALIGN( / );
__end__ = . ;
_end = .; PROVIDE (end = .);
. = DATA_SEGMENT_END (.);
/* Stabs debugging sections. */
.stab : { *(.stab) }
.stabstr : { *(.stabstr) }
.stab.excl : { *(.stab.excl) }
.stab.exclstr : { *(.stab.exclstr) }
.stab.index : { *(.stab.index) }
.stab.indexstr : { *(.stab.indexstr) }
.comment : { *(.comment) }
/* DWARF debug sections.
Symbols in the DWARF debugging sections are relative to the beginning
of the section so we begin them at 0. */
/* DWARF 1 */
.debug : { *(.debug) }
.line : { *(.line) }
/* GNU DWARF 1 extensions */
.debug_srcinfo : { *(.debug_srcinfo) }
.debug_sfnames : { *(.debug_sfnames) }
/* DWARF 1.1 and DWARF 2 */
.debug_aranges : { *(.debug_aranges) }
.debug_pubnames : { *(.debug_pubnames) }
/* DWARF 2 */
.debug_info : { *(.debug_info .gnu.linkonce.wi.*) }
.debug_abbrev : { *(.debug_abbrev) }
.debug_line : { *(.debug_line) }
.debug_frame : { *(.debug_frame) }
.debug_str : { *(.debug_str) }
.debug_loc : { *(.debug_loc) }
.debug_macinfo : { *(.debug_macinfo) }
/* SGI/MIPS DWARF 2 extensions */
.debug_weaknames : { *(.debug_weaknames) }
.debug_funcnames : { *(.debug_funcnames) }
.debug_typenames : { *(.debug_typenames) }
.debug_varnames : { *(.debug_varnames) }
/* DWARF 3 */
.debug_pubtypes : { *(.debug_pubtypes) }
.debug_ranges : { *(.debug_ranges) }
.gnu.attributes : { KEEP (*(.gnu.attributes)) }
.note.gnu.arm.ident : { KEEP (*(.note.gnu.arm.ident)) }
/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) }
} ==================================================

  现在不使用默认的BSS段,使用自己写的BSS段。

OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm",
"elf32-littlearm")
OUTPUT_ARCH(arm)
ENTRY(_start)
SECTIONS
{
. = 0x50000000; .text : {
start.o
*(.text)
}
. = ALIGN(); laomi_data_start = .;
.laomi : {
*(.laomi)
}
laomi_data_end = .; .data : {
*(.data)
}
. = ALIGN(); _bss_start = .;
.bss : {
*(.bss)
}
. = ALIGN();
_bss_end = .;
}

ld.lds

 #include <led.h>
#include <key.h>
#include <lib.h>
#include <uart.h>
#include <backlight.h>
#include <lcd.h>
#include <mmu.h> u32 *T = (void *)0x60000000; int var0;
int var1 = ; int data = ; int glb0 __attribute__ ((unused, section(".jason")))= ;
int glb1 __attribute__ ((unused, section(".jason")))= ;
int glb2 __attribute__ ((unused, section(".jason")))= ;
int glb3 __attribute__ ((unused, section(".jason")))= ; extern int jason_data_start;
extern int jason_data_end; void entry(void)
{
int *p = &jason_data_start; while (p < &jason_data_end) {
printf("*p = %d\n", *p);
p++;
}
}

entry.c

 .PHONE:clean

 TARGET        := arm
BIN := $(TARGET).bin
LDADD := 0x50000000
ASM := start.o
OBJS := entry.o lib.o mmu.o
CROSS_COMPILE := arm-linux-
CC := $(CROSS_COMPILE)gcc
LD := $(CROSS_COMPILE)ld
OBJCOPY := $(CROSS_COMPILE)objcopy
NM := $(CROSS_COMPILE)nm
OBJDUMP := $(CROSS_COMPILE)objdump all:$(TARGET)
$(OBJCOPY) -O binary $< $(BIN)
$(TARGET):$(ASM) $(OBJS)
$(LD) $(ASM) $(OBJS) -Tld.lds -o $@ %.o:%.S
$(CC) -c $^
%.o:%.c
$(CC) -c $^ -Iinclude -Wall -fno-builtin clean:
rm -f *.o $(BIN) $(TARGET)

Makefile

并且指定链接脚本,拿到结果

exynos4412—链接脚本复习的更多相关文章

  1. u-boot链接脚本分析

    eclipse 64位下载地址:http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release ...

  2. 驱动开发学习笔记. 0.07 Uboot链接地址 加载地址 和 链接脚本地址

    驱动开发学习笔记. 0.07 Uboot链接地址 加载地址 和 链接脚本地址 最近重新看了乾龙_Heron的<ARM 上电启动及 Uboot 代码分析>(下简称<代码分析>) ...

  3. [转]Linux下的lds链接脚本详解

    转载自:http://linux.chinaunix.net/techdoc/beginner/2009/08/12/1129972.shtml     一. 概论 每一个链接过程都由链接脚本(lin ...

  4. Linux下的lds链接脚本基础

    转载:http://soft.chinabyte.com/os/104/12255104.shtml   今天在看uboot引导Linux部分,发现要对链接脚本深入了解,才能知道各个目标文件的内存分布 ...

  5. Linux下的lds链接脚本简介

    转载:http://hubingforever.blog.163.com/blog/static/171040579201192472552886/   一. 概论 每一个链接过程都由链接脚本(lin ...

  6. 链接脚本之LMA VMA解释

    链接脚本中的LMA和VMA是什么意思.这个问题纠结了一段时间,今天在看<ARM体系结构与编程>时,豁然开朗,写下自己的认识.分享例如以下: LMA:载入地址 位于存储器中的地址  LOAD ...

  7. 第2阶段——编写uboot之硬件初始化和制作链接脚本lds(1)

    目标: 1.关看门狗 2.设置时钟 3.初始化SDRAM (初始化寄存器以及清除bss段) 4.重定位 (将nand/nor中代码COPY到链接地址上,需要初始化nandflash,读flash) 5 ...

  8. makefile使用.lds链接脚本以及 $@ ,$^, $,< 解析

    先来分析一个简单的.lds链接脚本 例1,假如现在有head.c init.c nand.c main.c这4个文件: 1.1 首先创建链接脚本nand.lds: SECTIONS { firtst ...

  9. 裸板驱动总结(makefile+lds链接脚本+裸板调试)

    在裸板2440中,当我们使用nand启动时,2440会自动将前4k字节复制到内部sram中,如下图所示: 然而此时的SDRAM.nandflash的控制时序等都还没初始化,所以我们就只能使用前0~40 ...

随机推荐

  1. SQL点点滴滴_公用表表达式(CTE)递归的生成帮助数据

    本文的作者辛苦了,版权问题特声明本文出处:http://www.cnblogs.com/wy123/p/5960825.html 工作有时候会需要一些帮助数据,必须需要连续的数字,连续间隔的时间点,连 ...

  2. Python学习---Django的新工程设置模板

    该模板完全可以在创建好新工程后进行部分代码替换 创建app01的  python startapp app01   创建static子目录 settings.py """ ...

  3. 点击键盘上的“Next”button实现文本框焦点跳转

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/quanqinayng/article/details/24405431 - (BOOL)textFi ...

  4. LCTF wp简单复现

    1.T4lk 1s ch34p,sh0w m3 the sh31l 代码如下: <?php $SECRET = `../read_secret`; $SANDBOX = "../dat ...

  5. 【Vue】安装(NPM 方法)

    [Vue2.0 新手完全填坑攻略——从环境搭建到发布]http://www.jianshu.com/p/5ba253651c3b 1.在用 Vue.js 构建大型应用时推荐使用 NPM 安装 2.Vu ...

  6. selenium以及浏览器驱动下载安装

    1.下载selenium压缩包 http://pypi.python.org/pypi/selenium 下载后压缩在python文件下的lib>site-package文件夹下 2.进入sel ...

  7. [转]MVP+WCF+三层结构搭建项目框架

    最近,我一直在重构之前做的一个项目,在这个过程中感慨万千.原先的项目是一个运用了WCF的C/S系统,在客户端运用了MVC模式,但MVC的View.Model耦合以及WCF端分布式欠佳等问题让我有了重构 ...

  8. C# - 静态类和静态构造函数

    一个类只能有一个静态构造函数,该构造函数不能有访问修饰符,不能带任何参数,不能直接调用,只能在: 1 创建包含静态构造函数的类实例时 2 访问包含静态构造函数的静态成员时 会先调用静态构造函数,无论创 ...

  9. jmeter接口测试2-断言

    接上篇 要想更好的查看接口测试结果,可以添加断言 举一个最简单的响应断言的例子 前提环境:根据接口文档可知,待测试接口返回值1,-1,-2,-3 (1)添加断言 (2)设置断言内容,看响应的内容是否含 ...

  10. DataFrame查找

    一 通过索引取数据 (ix/loc/iloc) loc (根据索引名称取数据 , 适合多列) iloc (根据索引序号取数据,   适合多列) at  (和loc类似,只用于取单列, 性能更好) ia ...