History

_end symbol definition fix - fixed section alignment logic

bellard committed 22 years ago

Commit ff3a5da1 parent 0bd402d1 file · +26 −14Browse files

Unified · Split

tccelf.c+26−14
@@ -1081,8 +1081,11 @@ int tcc_output_file(TCCState *s1, const char *filename) · 1080 unmodified lines
10811081 file_type = s1->output_type;
10821082 s1->nb_errors = 0;
10831083
1084− if (file_type != TCC_OUTPUT_OBJ)
1084+ if (file_type != TCC_OUTPUT_OBJ) {
1085+ relocate_common_syms();
1086+
10851087 tcc_add_runtime(s1);
1088+ }
10861089
10871090 phdr = NULL;
10881091 section_order = NULL;
@@ -1093,8 +1096,6 @@ int tcc_output_file(TCCState *s1, const char *filename) · 4 unmodified lines
10931096
10941097 if (file_type != TCC_OUTPUT_OBJ) {
10951098
1096− relocate_common_syms();
1097−
10981099 if (!s1->static_link) {
10991100 const char *name;
11001101 int sym_index, index;
@@ -1312,18 +1313,29 @@ int tcc_output_file(TCCState *s1, const char *filename) · 211 unmodified lines
13121313 file_offset = sizeof(Elf32_Ehdr) + phnum * sizeof(Elf32_Phdr);
13131314 if (phnum > 0) {
13141315 /* compute section to program header mapping */
1315− if (file_type == TCC_OUTPUT_DLL)
1316− addr = 0;
1317− else
1318− addr = ELF_START_ADDR;
1319−
1316+ if (s1->has_text_addr) {
1317+ int a_offset, p_offset;
1318+ addr = s1->text_addr;
1319+ /* we ensure that (addr % ELF_PAGE_SIZE) == file_offset %
1320+ ELF_PAGE_SIZE */
1321+ a_offset = addr & (ELF_PAGE_SIZE - 1);
1322+ p_offset = file_offset & (ELF_PAGE_SIZE - 1);
1323+ if (a_offset < p_offset)
1324+ a_offset += ELF_PAGE_SIZE;
1325+ file_offset += (a_offset - p_offset);
1326+ } else {
1327+ if (file_type == TCC_OUTPUT_DLL)
1328+ addr = 0;
1329+ else
1330+ addr = ELF_START_ADDR;
1331+ /* compute address after headers */
1332+ addr += (file_offset & (ELF_PAGE_SIZE - 1));
1333+ }
1334+
13201335 /* dynamic relocation table information, for .dynamic section */
13211336 rel_size = 0;
13221337 rel_addr = 0;
13231338
1324− /* compute address after headers */
1325− addr += (file_offset & (ELF_PAGE_SIZE - 1));
1326−
13271339 /* leave one program header for the program interpreter */
13281340 ph = &phdr[0];
13291341 if (interp)
@@ -1374,11 +1386,11 @@ int tcc_output_file(TCCState *s1, const char *filename) · 44 unmodified lines
13741386 section_order[sh_order_index++] = i;
13751387
13761388 /* section matches: we align it and add its size */
1377− tmp = file_offset;
1378− file_offset = (file_offset + s->sh_addralign - 1) &
1389+ tmp = addr;
1390+ addr = (addr + s->sh_addralign - 1) &
13791391 ~(s->sh_addralign - 1);
1392+ file_offset += addr - tmp;
13801393 s->sh_offset = file_offset;
1381− addr += file_offset - tmp;
13821394 s->sh_addr = addr;
13831395
13841396 /* update program header infos */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t