From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,9a2a420ec841e44c X-Google-Attributes: gidfee84,public From: Barry Andreasen Subject: Re: libcurses and patches for 4.0 Date: 1999/08/10 Message-ID: <37B08BFD.8B7E2E60@zk3.dec.com>#1/1 X-Deja-AN: 511504566 Content-Transfer-Encoding: 7bit Organization: Digital Equipment Corporation Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 Reply-To: bja@zk3.dec.com Newsgroups: comp.unix.osf.osf1 After working with Jon on this we have isolated the problem and I thought that posting the results would be beneficial to other developers as well. I tried to post this reply yesterday, but somehow I goofed since I don't see it, but if this is a second, please excuse the redundancy. In debugging the application Jon mentioned, it was found that the segv was occurring in the application code, when it tried to write to an invalid address. Further investigation found that address was expected to be to a global application variable, but the variable involved was also declared as a global variable with a similar definition in the curses library. While the application source code included a definition for the pointer, the linker and loader had resolved the address to be in the library memory allocation. After some research we learned that during compilation, the linker categorizes each variable. In the general case, the linker, when it finds new declarations will allocate space in the local memory region and categorize the variable as an 'allocated common' (odump -Dtv libcurses.so). When the curses library was built, this variable was unique and therefore generated an allocated region and became a GLOBAL ACOMM. However, when the linker finds an existing entry for a new variable (from a library), it does not do the allocation, and enters the variable as a simple common (COMM) and uses the offset to the existing allocated space from the ACOMM variable (odump -Dgv ). Previous versions of the libcurses.so ignored this violation, and fortunately functioned correctly, but the updated library versions blocked this violation and uncovered the memory overwrite, causing the application to segv. Since the specification for the curses interface indicates that certain variable names are reserved for the library implementation (this variable falls into that category), the solution is rename the application variable or force the local application declaration to do an allocation in the application data space by including an assignment in the declaration i.e. char *BC=NULL; This will cause the linker to classify the variable as DATA and place it in the application DATA space. When the loader encounters the variable, as data, it will use the local memory storage instead of writing to the library memory area. -b In article <7ml487$lbg$1@nnrp1.deja.com>, jhitchcock@my-deja.com wrote: > There are a lot of patches to libcurses available for 4.0, but it seems that > the libraries are in general incompatible with one another. > > We have a program that was built on 4.0D (without any patches) and it runs > OK on that system. When run on a patched 4.0D it fails with "error -1 bad > termcap". When run on 4.0E it core dumps. > > Can anyone suggest how we can get a library on patched 4.0D, 4.0E, 4.0F, > ... systems which is compatible with the original 4.0D library. Or does > anyone know which is the "correct" library to link with to enable use on > future systems. > > The program is linked using the default shared library (-lcurses) and it > uses tgetent(), tgetflag(), tgetnum() and tgetstr() to get capabilities: > > am bs hs mi ms pt xs sg ug li co ws ae al as bc bt cd ce cl cm cs dc dl dm do ed ei > fs ho ic im le ll nd se sf so sr te ti > ts uc ue up us vb ke ks ve vi bt kd kh kl kr ku CC k[0-9] K[0-9] l[0-9] L[0-9] > > (I know these functions are marked "TO BE WITHDRAWN" in the Single UNIX > Specification, but they are there, and they work on almost all Unixes.) > > The patches I know of are: > Digital UNIX 4.0D patches 374.00 374.03 408.02 > Digital UNIX 4.0E patches 31.00 123.00 277.00 278.00 > Tru64 UNIX 4.0F patches 46.00 69.00 > > Thanks, > > Jon Hitchcock