{"action":"created","issue":{"url":"https://api.github.com/repos/ps2dev/ps2sdk/issues/73","repository_url":"https://api.github.com/repos/ps2dev/ps2sdk","labels_url":"https://api.github.com/repos/ps2dev/ps2sdk/issues/73/labels{/name}","comments_url":"https://api.github.com/repos/ps2dev/ps2sdk/issues/73/comments","events_url":"https://api.github.com/repos/ps2dev/ps2sdk/issues/73/events","html_url":"https://github.com/ps2dev/ps2sdk/issues/73","id":340990419,"node_id":"MDU6SXNzdWUzNDA5OTA0MTk=","number":73,"title":"IOP export table declaration causes relocation truncated warning when mgpopt is enabled","user":{"login":"sp193","id":3446348,"node_id":"MDQ6VXNlcjM0NDYzNDg=","avatar_url":"https://avatars1.githubusercontent.com/u/3446348?v=4","gravatar_id":"","url":"https://api.github.com/users/sp193","html_url":"https://github.com/sp193","followers_url":"https://api.github.com/users/sp193/followers","following_url":"https://api.github.com/users/sp193/following{/other_user}","gists_url":"https://api.github.com/users/sp193/gists{/gist_id}","starred_url":"https://api.github.com/users/sp193/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sp193/subscriptions","organizations_url":"https://api.github.com/users/sp193/orgs","repos_url":"https://api.github.com/users/sp193/repos","events_url":"https://api.github.com/users/sp193/events{/privacy}","received_events_url":"https://api.github.com/users/sp193/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":8,"created_at":"2018-07-13T11:53:09Z","updated_at":"2018-07-14T04:13:28Z","closed_at":null,"author_association":"MEMBER","body":"As of commit 587cad4, these macros have been added to defs.h, to allow the programmer to manipulate the $gp register when required:\r\n\r\n- SetGP\r\n-GetGP\r\n-ReplaceGP\r\n-SetModuleGP\r\n\r\nUSBD will now use $gp, and also supports restoring the driver & caller's $gp. This was a documented function of USBD, which our homebrew module was lacking.\r\n\r\nHowever, the G parameter is currently set to 19. I found that I couldn't increase it, as with the SMAP module.\r\nGoing beyond 19 would result in a linker error like this:\r\n`` iop-gcc -D_IOP -fno-builtin -Os -G0 -Wall  -Isrc/ -Isrc/include -Iinclude/ -I/home/nozomi/PS2/ps2sdk/iop/kernel/include -I/home/nozomi/PS2/ps2sdk/common/include -mgpopt -G8192 -o irx/usbd.irx obj/hcd.o obj/hub.o obj/interface.o obj/mem.o obj/usbd.o obj/usbio.o obj/driver.o obj/imports.o obj/exports.o -nostdlib -s\r\nobj/usbd.o(.text+0x700): In function `_start':\r\nsrc/usbd.c: relocation truncated to fit: R_MIPS_GPREL16 _exp_usbd\r\ncollect2: ld returned 1 exit status\r\n``\r\n\r\nI think it might have something to do with the [definition of the export table](https://github.com/ps2dev/ps2sdk/blob/master/iop/kernel/include/irx.h#L85), which has the fptrs field defined as an zero-length array at +0x14 (20th byte mark).\r\nRemoving the declaration of the _exp_usbd structure and its corresponding call to RegisterLibraryEntries will inhibit the warning, even if I increased the G-parameter to as high as 8192.\r\n\r\nAnd so I think it might have got to do with the undefined size of fptrs, but I am not well-versed with the GCC/LD internals.\r\n\r\nFor now, I have a patch that replaces the use of struct irx_export_table with iop_libhead_t, which represents the export table after linking: https://github.com/sp193/ps2sdk/tree/libhead\r\nSince it does not define the export table body (fptrs), it results in no linker error.\r\nOther than solving this problem, it also represents the import and export tables after linking (rather than their forms before linking). So these new structures can be used together with the ones in irx.h for complete representation of the import and export tables.\r\n\r\nThe only bad thing about doing this, is that there will be warnings in older projects, but I guess that is a small price to pay.\r\n\r\nDoes anybody have any comments or a better way to solve this?"},"comment":{"url":"https://api.github.com/repos/ps2dev/ps2sdk/issues/comments/404997196","html_url":"https://github.com/ps2dev/ps2sdk/issues/73#issuecomment-404997196","issue_url":"https://api.github.com/repos/ps2dev/ps2sdk/issues/73","id":404997196,"node_id":"MDEyOklzc3VlQ29tbWVudDQwNDk5NzE5Ng==","user":{"login":"sp193","id":3446348,"node_id":"MDQ6VXNlcjM0NDYzNDg=","avatar_url":"https://avatars1.githubusercontent.com/u/3446348?v=4","gravatar_id":"","url":"https://api.github.com/users/sp193","html_url":"https://github.com/sp193","followers_url":"https://api.github.com/users/sp193/followers","following_url":"https://api.github.com/users/sp193/following{/other_user}","gists_url":"https://api.github.com/users/sp193/gists{/gist_id}","starred_url":"https://api.github.com/users/sp193/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sp193/subscriptions","organizations_url":"https://api.github.com/users/sp193/orgs","repos_url":"https://api.github.com/users/sp193/repos","events_url":"https://api.github.com/users/sp193/events{/privacy}","received_events_url":"https://api.github.com/users/sp193/received_events","type":"User","site_admin":false},"created_at":"2018-07-14T04:13:28Z","updated_at":"2018-07-14T04:13:28Z","author_association":"MEMBER","body":"I seem to have blundered somewhere again. :(\r\nRemoving those fields (through new structure or not) doesn't help! So I have no idea why I get such linker errors.\r\n\r\nAs for the fptrs field and friends: I seem to have been mistaken again. Not only does omitting it not help, you're probably right about it not being used (the macros for generating import & export tables work differently)... so everything here has been a waste of time.\r\n\r\nAs for the complexity: if used right, it would reduce the number of immediate loads **very** slightly. I have observed that programs compiled with mgpopt are usually slightly shorter too.\r\n\r\nIt is especially useful if the function will access a global structure across **multiple** function calls.\r\nFor example, take [smap_init of smap.c](https://github.com/ps2dev/ps2sdk/blob/master/iop/network/smap/src/smap.c#L837). It has a series of strcmp operations, with the string literal being a static constant.\r\n\r\nWithout mgpopt, the full address of the globals and constants must be loaded (with lui and addiu/ori) for each evaluation.\r\n```    1604:\t8e050000 \tlw\ta1,0(s0)\r\n    1608:\t3c040000 \tlui\ta0,0x0\r\n    160c:\t0c000000 \tjal\t0 <strcmp>\r\n    1610:\t2484041c \taddiu\ta0,a0,1052\r\n    1614:\t14400128 \tbnez\tv0,1ab8 <smap_init+0x524>\r\n    1618:\t24020001 \tli\tv0,1\r\n    161c:\t3c010000 \tlui\tat,0x0\r\n    1620:\tac220008 \tsw\tv0,8(at)\r\n```\r\nWith mgpopt:\r\n```    157c:\t8e050000 \tlw\ta1,0(s0)\r\n    1580:\t2784c0d0 \taddiu\ta0,gp,-16176\r\n    1584:\t0c000000 \tjal\t0 <strcmp>\r\n    1588:\t00000000 \tnop\r\n    158c:\t14400127 \tbnez\tv0,1a2c <smap_init+0x520>\r\n    1590:\t24020001 \tli\tv0,1\r\n    1594:\taf82c018 \tsw\tv0,-16360(gp)\r\n```\r\n\r\nOf course, if you replaced $gp in a function that does not refer to many globals, then the trade-off becomes minimal (might even add onto the complexity).\r\n\r\nThanks for discussing this matter with me, even thought it didn't exactly lead to anything we can use directly yet."}}
{"actor":{"display_login":"sp193"}}