From: Luke Lee Newsgroups: comp.os.msdos.djgpp Subject: Question about LD.EXE ... Date: Fri, 07 Feb 1997 18:10:06 +0800 Organization: Common Forth Labortory Lines: 100 Message-ID: <32FAFF7E.6DBB@ms2.hinet.net> Reply-To: comforth AT ms2 DOT hinet DOT net NNTP-Posting-Host: @140.109.249.30 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Hi, everyone : I'm using ld.exe's facility to allocate an array at a specific location, say 0x140000, but when I try to access that memory block , I always got the fatal SIGSEGV. Could someone tell me how can I prevent this problem ? I've written a simple testing program downthere, please take a look ... Thank. Any help will be very appreciated ! Why am I doing that ? Well, I got some non-relocatable codes which need to be loaded at a specific location, I've try some methods : 1. Put that memory block inside '.bss' section so that it could be allocated before 'main()' ... but I am not able to specify the precise location by : . = 0x140000; 2. Allocate small blocks of memory before 0x140000, until it is about to reach 0x140000, then allocate my memory block. This works fine under MSDOS but failed under Win95 DOS box ( even if I followed DJGPP's FAQ to adjust DOS box's property ... ) 3. The following method, however, I don't know how to prevent that segment violation fault SIGSEGV . --------- Exmaple code --------- System : Cyrix 6x86 P150+ ; 32M RAM , 512K cache OS : DOS 6.22; DOS 7.0+Windows 95 DJGPP : version 2.01 ----- FILE 1 : TEST.C -------------------------------------------------- #include extern int TEST_ARRAY[0x40000] ; /* total 1M bytes */ void main() { int i; for (i=0; i<0x40000; i++ ) { printf( "i=%5X\t", i ); fflush( stdout ); TEST_ARRAY[i] = 0x55AA55AA; } } /* FootNote : this program produce SIGSEGV when 'i=0' */ ----- FILE 2 : TEST.LD ------------------------------------------------ ----- This file is modified from /djgpp/lib/djgpp.djl OUTPUT_FORMAT("coff-go32") ENTRY(start) SECTIONS { .text 0x1000+SIZEOF_HEADERS : { *(.text) etext = . ; _etext = .; . = ALIGN(0x200); } .data ALIGN(0x200) : { djgpp_first_ctor = . ; *(.ctor) djgpp_last_ctor = . ; djgpp_first_dtor = . ; *(.dtor) djgpp_last_dtor = . ; *(.data) edata = . ; _edata = .; . = ALIGN(0x200); } .bss SIZEOF(.data) + ADDR(.data) : { *(.bss) *(COMMON) end = . ; _end = .; . = 0xCCCCC; _Not_CCCCC = . ; . = ALIGN(0x200); } .TEST 0x140000 : { _TEST_ARRAY = . ; . += 0x100000; _END_TEST_ARRAY = . ; } = 0x0000 } ----- FILE 3 : MAKETEST.BAT -------------------------------------------- gcc -g test.c -o test -Wl,-Map,TEST.MAP,-T,TEST.LD ----- END OF ALL FILES ------------------------------------------------- After MAKETEST, please reference to TEST.MAP, the logical address specified at TEST.LD '_Not_CCCCC' is indeed not 0xCCCCC. Even if . = ABSOLUTE( 0xCCCCC ); Why is that ??? Sincerely, Luke Lee