From a86b7030826aaac6dcea7832385b467bea7d3618 Mon Sep 17 00:00:00 2001 From: "Steven R. Loomis" Date: Sat, 4 Nov 2000 02:16:12 +0000 Subject: [PATCH] ICU-683 symbols collision fix for aix, solaris, linux X-SVN-Rev: 2873 --- icu4c/source/common/udata.c | 97 +++++++++++++++++++++++-- icu4c/source/config/mh-aix | 7 +- icu4c/source/config/mh-linux | 17 ++++- icu4c/source/config/mh-solaris | 6 +- icu4c/source/test/cintltst/udatatst.c | 18 ++++- icu4c/source/tools/genccode/Makefile.in | 2 +- icu4c/source/tools/genccode/genccode.c | 5 ++ icu4c/source/tools/gencmn/Makefile.in | 2 +- icu4c/source/tools/gencmn/gencmn.c | 4 + icu4c/source/tools/pkgdata/dllmode.c | 19 ++++- 10 files changed, 157 insertions(+), 20 deletions(-) diff --git a/icu4c/source/common/udata.c b/icu4c/source/common/udata.c index 69e0ad63a5c..db3c7aecb98 100644 --- a/icu4c/source/common/udata.c +++ b/icu4c/source/common/udata.c @@ -165,10 +165,33 @@ # define NO_LIBRARY NULL # define IS_LIBRARY(lib) ((lib)!=NULL) + + +#ifndef UDATA_DEBUG # define LOAD_LIBRARY(path, basename) dlopen(path, RTLD_LAZY|RTLD_GLOBAL) # define UNLOAD_LIBRARY(lib) dlclose(lib) - # define GET_LIBRARY_ENTRY(lib, entryName) dlsym(lib, entryName) +#else + void *LOAD_LIBRARY(const char *path, const char *basename) + { + void *rc; + rc = dlopen(path, RTLD_LAZY|RTLD_GLOBAL); + fprintf(stderr, "Load [%s|%s] -> %p\n", path, basename, rc); + return rc; + } + void UNLOAD_LIBRARY(void *lib) + { + dlclose(lib); + fprintf(stderr, "Unload [%p]\n", lib); + } + void * GET_LIBRARY_ENTRY(void *lib, const char *entryName) + { + void *rc; + rc = dlsym(lib, entryName); + fprintf(stderr, "Get[%p] %s->%p\n", lib, entryName, rc); + return rc; + } +#endif /* End of dlopen or compatible functions */ #else /* unknown platform, no DLL implementation */ @@ -481,6 +504,12 @@ offsetTOCLookupFn(const UDataMemory *pData, const char *tocEntryName, const char *dllEntryName, UErrorCode *pErrorCode) { +#ifdef UDATA_DEBUG + fprintf(stderr, "offsetTOC[%p] looking for %s/%s\n", + pData, + tocEntryName,dllEntryName); +#endif + if(pData->toc!=NULL) { const char *base=(const char *)pData->toc; uint32_t *toc=(uint32_t *)pData->toc; @@ -500,11 +529,21 @@ offsetTOCLookupFn(const UDataMemory *pData, if(uprv_strcmp(tocEntryName, base+toc[2*start])==0) { /* found it */ +#ifdef UDATA_DEBUG + fprintf(stderr, "Found: %p\n",(base+toc[2*start+1])); +#endif return (const DataHeader *)(base+toc[2*start+1]); } else { +#ifdef UDATA_DEBUG + fprintf(stderr, "Not found.\n"); +#endif return NULL; } } else { +#ifdef UDATA_DEBUG + fprintf(stderr, "returning header\n"); +#endif + return pData->pHeader; } } @@ -514,6 +553,11 @@ pointerTOCLookupFn(const UDataMemory *pData, const char *tocEntryName, const char *dllEntryName, UErrorCode *pErrorCode) { +#ifdef UDATA_DEBUG + fprintf(stderr, "ptrTOC[%p] looking for %s/%s\n", + pData, + tocEntryName,dllEntryName); +#endif if(pData->toc!=NULL) { const PointerTOCEntry *toc=(const PointerTOCEntry *)((const uint32_t *)pData->toc+2); uint32_t start, limit, number; @@ -521,6 +565,12 @@ pointerTOCLookupFn(const UDataMemory *pData, /* perform a binary search for the data in the common data's table of contents */ start=0; limit=*(const uint32_t *)pData->toc; /* number of names in this table of contents */ + +#ifdef UDATA_DEBUG + fprintf(stderr, " # of ents: %d\n", limit); + fflush(stderr); +#endif + while(startpHeader; +#ifdef UDATA_DEBUG + fprintf(stderr, "Returning header\n"); +#endif + return pData->pHeader; } } @@ -556,7 +617,7 @@ dllTOCLookupFn(const UDataMemory *pData, /* common library functions ------------------------------------------------- */ -static UDataMemory commonICUData={ NULL }; + static UDataMemory commonICUData={ NULL }; static void setCommonICUData(UDataMemory *pData) { @@ -921,9 +982,17 @@ doOpenChoice(const char *path, const char *type, const char *name, uprv_memset(&dataMemory, 0, sizeof(UDataMemory)); pathBuffer[0]=0; pCommonData=openCommonData(&dataMemory, path, isICUData, pathBuffer, &errorCode); +#ifdef UDATA_DEBUG + fprintf(stderr, "commonData;%p\n", pCommonData); + fflush(stderr); +#endif + if(U_SUCCESS(errorCode)) { /* look up the data piece in the common data */ pHeader=pCommonData->lookupFn(pCommonData, tocEntryName, dllEntryName, &errorCode); +#ifdef UDATA_DEBUG + fprintf(stderr, "Common found: %p\n", pHeader); +#endif if(pHeader!=NULL) { /* data found in the common data, test it */ if(pHeader->dataHeader.magic1==0xda && pHeader->dataHeader.magic2==0x27 && @@ -949,9 +1018,15 @@ doOpenChoice(const char *path, const char *type, const char *name, pEntryData->parent=pCommonData; pEntryData->pHeader=pHeader; pEntryData->flags=(pCommonData->flags&DATA_MEMORY_TYPE_MASK)|1UL<flags&(1UL< /dev/null 2>&1' +## BIR - bind with internal references [so app data and icu data doesn't collide] +BIR_LDFLAGS= -E$(NAME).map -bnoexpall +BIR_CPPFLAGS= -DU_HAVE_BIND_INTERNAL_REFERENCES +BIR_DEPS= $(NAME).map + ## End Aix-specific setup diff --git a/icu4c/source/config/mh-linux b/icu4c/source/config/mh-linux index b673c8880b2..acc8c179285 100644 --- a/icu4c/source/config/mh-linux +++ b/icu4c/source/config/mh-linux @@ -3,7 +3,7 @@ ## Copyright (c) 1999-2000, International Business Machines Corporation and ## others. All Rights Reserved. ## -## $Id: mh-linux,v 1.22 2000/10/18 20:35:21 yves Exp $ +## $Id: mh-linux,v 1.23 2000/11/04 02:16:11 srl Exp $ ## Commands to generate dependency files GEN_DEPS.c= $(CC) -E -MM $(DEFS) $(CPPFLAGS) @@ -84,13 +84,13 @@ LIBUSTDIO= -L$(top_builddir)/extra/ustdio -lustdio %.d: $(srcdir)/%.c @echo "Generating dependency information for $<" @$(SHELL) -ec '$(GEN_DEPS.c) $< \ - | sed '\''s/\($*\)\.o[ :]*/\1.o $@ : /g'\'' > $@; \ + | sed '\''s%\($*\)\.o[ :]*%\1.o $@ : %g'\'' > $@; \ [ -s $@ ] || rm -f $@' %.d: $(srcdir)/%.cpp @echo "Generating dependency information for $<" @$(SHELL) -ec '$(GEN_DEPS.cc) $< \ - | sed '\''s/\($*\)\.o[ :]*/\1.o $@ : /g'\'' > $@; \ + | sed '\''s%\($*\)\.o[ :]*%\1.o $@ : %g'\'' > $@; \ [ -s $@ ] || rm -f $@' ## Versioned libraries rules @@ -100,5 +100,16 @@ LIBUSTDIO= -L$(top_builddir)/extra/ustdio -lustdio %.$(SO): %.$(SO).$(SO_TARGET_VERSION_MAJOR) $(RM) $@ && ln -s $*.$(SO).$(SO_TARGET_VERSION) $@ +## Bind internal references + +# LDflags that pkgdata will use +BIR_LDFLAGS= -Wl,-Bsymbolic + +# CPPflags for genccode/gencmn +BIR_CPPFLAGS= -DU_HAVE_BIND_INTERNAL_REFERENCES + +# Dependencies [i.e. map files] for the final library +BIR_DEPS= + ## End Linux-specific setup diff --git a/icu4c/source/config/mh-solaris b/icu4c/source/config/mh-solaris index 14de0c3b77b..3587319e7ac 100644 --- a/icu4c/source/config/mh-solaris +++ b/icu4c/source/config/mh-solaris @@ -3,7 +3,7 @@ ## Copyright (c) 1999-2000, International Business Machines Corporation and ## others. All Rights Reserved. ## -## $Id: mh-solaris,v 1.20 2000/10/17 16:52:58 yves Exp $ +## $Id: mh-solaris,v 1.21 2000/11/04 02:16:11 srl Exp $ ## Flags for position independent code SHAREDLIBCFLAGS = -KPIC @@ -94,4 +94,8 @@ LIBUSTDIO= -L$(top_builddir)/extra/ustdio -lustdio %.$(SO): %.$(SO).$(SO_TARGET_VERSION_MAJOR) $(RM) $@ && ln -s $*.$(SO).$(SO_TARGET_VERSION) $@ +# +BIR_LDFLAGS= -Wl,-M,$(NAME).map -Wl,-B,symbolic -Wl,-B,eliminate +BIR_CPPFLAGS= -DU_HAVE_BIND_INTERNAL_REFERENCES +BIR_DEPS= $(NAME).map ## End Solaris-specific setup diff --git a/icu4c/source/test/cintltst/udatatst.c b/icu4c/source/test/cintltst/udatatst.c index 0445fd3d411..25173ddfbfe 100644 --- a/icu4c/source/test/cintltst/udatatst.c +++ b/icu4c/source/test/cintltst/udatatst.c @@ -572,6 +572,7 @@ void TestAppData() { UResourceBundle *icu, *app; UResourceBundle *tmp = NULL; + UResourceBundle *tmp2 = NULL; const UChar *appString; const UChar *icuString; @@ -590,6 +591,8 @@ void TestAppData() log_err("%s:%d: Couldn't open root ICU bundle- %s", __FILE__, __LINE__, u_errorName(status)); return; } + /* log_info("Open icu root: %s size_%d\n", u_errorName(status), ures_getSize(icu)); */ + status = U_ZERO_ERROR; app = ures_open(testPath, "root", &status); if(U_FAILURE(status)) @@ -597,6 +600,7 @@ void TestAppData() log_err("%s:%d: Couldn't open app ICU bundle [%s]- %s", __FILE__, __LINE__, testPath, u_errorName(status)); return; } + /* log_info("Open app: %s, size %d\n", u_errorName(status), ures_getSize(app)); */ tmp = ures_getByKey(icu, "Version", tmp, &status); if(U_FAILURE(status)) @@ -611,25 +615,30 @@ void TestAppData() log_err("%s:%d: Couldn't get string from Version string from ICU root bundle- %s", __FILE__, __LINE__, u_errorName(status)); return; } + /* log_info("icuString=%p - %s\n", icuString, austrdup(icuString)); */ - tmp = ures_getByKey(app, "Version", tmp, &status); + tmp2 = ures_getByKey(app, "Version", tmp2, &status); if(U_FAILURE(status)) { - log_err("%s:%d: Couldn't get Version string from App root bundle- %s", __FILE__, __LINE__, u_errorName(status)); + log_err("%s:%d: Couldn't get Version string from App root bundle- %s", __FILE__, __LINE__, u_errorName(status)); return; } - appString = ures_getString(tmp, &len, &status); + appString = ures_getString(tmp2, &len, &status); if(U_FAILURE(status)) { log_err("%s:%d: Couldn't get string from Version string from App root bundle- %s", __FILE__, __LINE__, u_errorName(status)); return; } + /* log_info("appString=%p - %s\n", appString, austrdup(appString)); */ + + if(!u_strcmp(icuString, appString)) { - log_err("%s:%d: Error! Expected ICU and App root version strings to be DIFFERENT but they are both %s\n", __FILE__, __LINE__, austrdup(appString)); + log_err("%s:%d: Error! Expected ICU and App root version strings to be DIFFERENT but they are both %s and %s\n", __FILE__, __LINE__, austrdup(icuString), + austrdup(appString)); } else { @@ -638,6 +647,7 @@ void TestAppData() } ures_close(tmp); + ures_close(tmp2); ures_close(icu); ures_close(app); diff --git a/icu4c/source/tools/genccode/Makefile.in b/icu4c/source/tools/genccode/Makefile.in index fef4c3f19ad..aa2e5a9b141 100644 --- a/icu4c/source/tools/genccode/Makefile.in +++ b/icu4c/source/tools/genccode/Makefile.in @@ -24,7 +24,7 @@ CLEANFILES = *~ $(DEPS) $(RES_FILES) $(TEST_FILES) TARGET = genccode DEFS = @DEFS@ -CPPFLAGS = @CPPFLAGS@ -I$(top_builddir)/common -I$(top_srcdir)/common -I$(srcdir)/../toolutil +CPPFLAGS = @CPPFLAGS@ -I$(top_builddir)/common -I$(top_srcdir)/common -I$(srcdir)/../toolutil $(BIR_CPPFLAGS) CFLAGS = @CFLAGS@ CXXFLAGS = @CXXFLAGS@ ENABLE_RPATH = @ENABLE_RPATH@ diff --git a/icu4c/source/tools/genccode/genccode.c b/icu4c/source/tools/genccode/genccode.c index a7902b9aca2..5caaa7d8322 100644 --- a/icu4c/source/tools/genccode/genccode.c +++ b/icu4c/source/tools/genccode/genccode.c @@ -66,6 +66,8 @@ main(int argc, char* argv[]) { /* read command line options */ argc=u_parseArgs(argc, argv, sizeof(options)/sizeof(options[0]), options); +#ifndef U_HAVE_BIND_INTERNAL_REFERENCES + if( (options[4].doesOccur) && uprv_strcmp(options[4].value, "icudata")) /* be consistent with gencmn! */ { uprv_strcpy(symPrefix, options[4].value); @@ -75,6 +77,9 @@ main(int argc, char* argv[]) { { symPrefix[0] = 0; } +#else + symPrefix[0] = 0; +#endif /* error handling, printing usage message */ if(argc<0) { diff --git a/icu4c/source/tools/gencmn/Makefile.in b/icu4c/source/tools/gencmn/Makefile.in index ff7adb51d77..082c4d60244 100644 --- a/icu4c/source/tools/gencmn/Makefile.in +++ b/icu4c/source/tools/gencmn/Makefile.in @@ -32,7 +32,7 @@ LINK = $(LINK.c) endif DEFS = @DEFS@ -CPPFLAGS = @CPPFLAGS@ -I$(top_builddir)/common -I$(top_srcdir)/common -I$(srcdir)/../toolutil +CPPFLAGS = @CPPFLAGS@ -I$(top_builddir)/common -I$(top_srcdir)/common -I$(srcdir)/../toolutil $(BIR_CPPFLAGS) CFLAGS = @CFLAGS@ CXXFLAGS = @CXXFLAGS@ ENABLE_RPATH = @ENABLE_RPATH@ diff --git a/icu4c/source/tools/gencmn/gencmn.c b/icu4c/source/tools/gencmn/gencmn.c index ce9b2642530..aa0845ae007 100644 --- a/icu4c/source/tools/gencmn/gencmn.c +++ b/icu4c/source/tools/gencmn/gencmn.c @@ -105,6 +105,7 @@ main(int argc, char* argv[]) { options[7].value=DATA_TYPE; argc=u_parseArgs(argc, argv, sizeof(options)/sizeof(options[0]), options); +#ifndef U_HAVE_BIND_INTERNAL_REFERENCES /* if it is ICU data.. no prefix. */ if(!uprv_strcmp(options[6].value, COMMON_DATA_NAME)) { @@ -115,6 +116,9 @@ main(int argc, char* argv[]) { uprv_strcpy(symPrefix, options[6].value); uprv_strcat(symPrefix, "_"); } +#else + symPrefix[0] = 0; +#endif /* error handling, printing usage message */ if(argc<0) { diff --git a/icu4c/source/tools/pkgdata/dllmode.c b/icu4c/source/tools/pkgdata/dllmode.c index 3d8614019e8..8790215e5fa 100644 --- a/icu4c/source/tools/pkgdata/dllmode.c +++ b/icu4c/source/tools/pkgdata/dllmode.c @@ -153,6 +153,8 @@ void pkg_mode_dll(UPKGOptions *o, FileStream *makefile, UErrorCode *status) T_FileStream_writeLine(makefile, tmp); sprintf(tmp, "TOCOBJ= %s_dat%s \n\n", o->shortName,OBJ_SUFFIX); T_FileStream_writeLine(makefile, tmp); + sprintf(tmp, "TOCSYM= %s_dat \n\n", o->shortName); + T_FileStream_writeLine(makefile, tmp); T_FileStream_writeLine(makefile, "BASE_OBJECTS= $(TOCOBJ) "); @@ -165,8 +167,8 @@ void pkg_mode_dll(UPKGOptions *o, FileStream *makefile, UErrorCode *status) T_FileStream_writeLine(makefile,"build-objs: $(SOURCES) $(OBJECTS)\n\n$(OBJECTS): $(SOURCES)\n\n"); #ifdef HPUX - T_FileStream_writeLine(makefile, "$(TARGETDIR)/$(TARGET): $(OBJECTS) $(HPUX_JUNK_OBJ) $(LISTFILES)\n" - "\t$(SHLIB.cc) -o $@ $(OBJECTS) $(HPUX_JUNK_OBJ)\n" + T_FileStream_writeLine(makefile, "$(TARGETDIR)/$(TARGET): $(OBJECTS) $(HPUX_JUNK_OBJ) $(LISTFILES) $(BIR_DEPS)\n" + "\t$(SHLIB.cc) -o $@ $(OBJECTS) $(HPUX_JUNK_OBJ) $(BIR_LDFLAGS)\n" "\t-ls -l $@\n\n"); T_FileStream_writeLine(makefile, "$(TEMP_DIR)/hpux_junk_obj.cpp:\n" @@ -176,8 +178,8 @@ void pkg_mode_dll(UPKGOptions *o, FileStream *makefile, UErrorCode *status) " $(COMPILE.cc) -o $@ $<\n" "\n"); #else - T_FileStream_writeLine(makefile, "$(TARGETDIR)/$(TARGET): $(OBJECTS) $(LISTFILES)\n" - "\t$(SHLIB.c) -o $@ $(OBJECTS)\n" + T_FileStream_writeLine(makefile, "$(TARGETDIR)/$(TARGET): $(OBJECTS) $(LISTFILES) $(BIR_DEPS)\n" + "\t$(SHLIB.c) -o $@ $(OBJECTS) $(BIR_LDFLAGS)\n" "\t-ls -l $@\n\n"); #endif @@ -187,6 +189,15 @@ void pkg_mode_dll(UPKGOptions *o, FileStream *makefile, UErrorCode *status) T_FileStream_writeLine(makefile, "install: $(TARGETDIR)/$(TARGET)\n" "\t$(INSTALL-L) $(TARGETDIR)/$(TARGET) $(INSTALLTO)/$(TARGET)\n\n"); +#ifdef U_SOLARIS + T_FileStream_writeLine(makefile, "$(NAME).map:\n\techo \"{global: $(TOCSYM); local: *; };\" > $@\n\n"); +#endif + +#ifdef AIX + T_FileStream_writeLine(makefile, "$(NAME).map:\n\techo \"$(TOCSYM)\" > $@\n\n"); +#endif + + *status = U_ZERO_ERROR; }